#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: Float.py
 @DateTime: 2025/6/21 22:03
 @SoftWare: PyCharm
 @Author  ：xsh
"""

from PyQt5 import Qt
import math
from decimal import Decimal
class Float(float):

    rel_tol: float = 0.0001

    def __lt__(self, other: (float, int, 'Float'), *args, **kwargs) -> bool:
        """小于（<）"""
        if isinstance(other, float):
            return Decimal(f'{self}') < Decimal(f'{other}')
        elif isinstance(other, int):
            return Decimal(f'{self}') < Decimal(f'{other}')
        elif isinstance(other, self.__class__):
            return Decimal(f'{self}') < Decimal(f'{other}')
        return False
    def __le__(self, other: (float, int, 'Float'), *args, **kwargs) -> bool:
        """小于等于（<=）"""
        if self.__eq__(other):
            return True
        if isinstance(other, float):
            return Decimal(f'{self}') < Decimal(f'{other}')
        elif isinstance(other, int):
            return Decimal(f'{self}') < Decimal(f'{other}')
        elif isinstance(other, self.__class__):
            return Decimal(f'{self}') < Decimal(f'{other}')
        return False
    def __eq__(self, other: (float, int, 'Float'), *args, **kwargs) -> bool:
        """等于（==）"""
        if isinstance(other, float):
            return math.isclose(float(self), float(other), rel_tol = self.rel_tol)
        elif isinstance(other, int):
            return math.isclose(float(self), float(other), rel_tol = self.rel_tol)
        elif isinstance(other, self.__class__):
            return math.isclose(float(self), float(other), rel_tol = self.rel_tol)
        return False
    def __ne__(self, other: (float, int, 'Float'), *args, **kwargs) -> bool:
        """不等于（!=）"""
        return not self.__eq__(other)
    def __gt__(self, other: (float, int, 'Float'), *args, **kwargs) -> bool:
        """大于（>）"""
        if isinstance(other, float):
            return Decimal(f'{self}') > Decimal(f'{other}')
        elif isinstance(other, int):
            return Decimal(f'{self}') > Decimal(f'{other}')
        elif isinstance(other, self.__class__):
            return Decimal(f'{self}') > Decimal(f'{other}')
        return False
    def __ge__(self, other: (float, int, 'Float'), *args, **kwargs) -> bool:
        """大于等于（>=）  """
        if self.__eq__(other):
            return True
        if isinstance(other, float):
            return Decimal(f'{self}') > Decimal(f'{other}')
        elif isinstance(other, int):
            return Decimal(f'{self}') > Decimal(f'{other}')
        elif isinstance(other, self.__class__):
            return Decimal(f'{self}') > Decimal(f'{other}')
        return False