码迷,mamicode.com
首页 > 其他好文 > 详细

float(浮点数)功能详解

时间:2016-01-14 14:14:16      阅读:597      评论:0      收藏:0      [点我收藏+]

标签:

class float(object):
    """
    float(x) -> floating point number
    
    Convert a string or number to a floating point number, if possible.
    """
    def as_integer_ratio(self):   
        """ 获取改值的最简比 """
        """
        float.as_integer_ratio() -> (int, int)

        Return a pair of integers, whose ratio is exactly equal to the original
        float and with a positive denominator.
        Raise OverflowError on infinities and a ValueError on NaNs.

        >>> (10.0).as_integer_ratio()
        (10, 1)
        >>> (0.0).as_integer_ratio()
        (0, 1)
        >>> (-.25).as_integer_ratio()
        (-1, 4)
        """
        pass
        print (float.as_integer_ratio(1.0))1

    def conjugate(self, *args, **kwargs): # real signature unknown
        """ Return self, the complex conjugate of any float. """
        pass

    def fromhex(self, string):   
        """ 将十六进制字符串转换成浮点型 """
        """
        float.fromhex(string) -> float
        
        Create a floating-point number from a hexadecimal string.
        >>> float.fromhex(‘0x1.ffffp10‘)
        2047.984375
        >>> float.fromhex(‘-0x1p-1074‘)
        -4.9406564584124654e-324
        """
        return 0.0
        

        def hex(self):   
        """ 返回当前值的 16 进制表示 """
        """
        float.hex() -> string
        
        Return a hexadecimal representation of a floating-point number.
        >>> (-0.1).hex()
        ‘-0x1.999999999999ap-4‘
        >>> 3.14159.hex()
        ‘0x1.921f9f01b866ep+1‘
        """
        return ""
        print (float.hex(1.0)) 0x1.0000000000000p+0

    def is_integer(self, *args, **kwargs): # real signature unknown
        """ Return True if the float is an integer. """
        pass

    def __abs__(self):   
        """ x.__abs__() <==> abs(x) """
        pass
        绝对值

    def __add__(self, y):   
        """ x.__add__(y) <==> x+y """
        pass
    加法
    
    def __coerce__(self, y):   
        """ x.__coerce__(y) <==> coerce(x, y) """
        pass
    
    
    def __divmod__(self, y):   
        """ x.__divmod__(y) <==> divmod(x, y) """
        pass
    print (float.__divmod__(4.0,2)) (2.0, 0.0) 浮点除,余小数
        
    def __div__(self, y):   
        """ x.__div__(y) <==> x/y """
        pass
        

    def __eq__(self, y):   
        """ x.__eq__(y) <==> x==y """
        pass
        print(float.__eq__(1.0,1.0)) True 是否相等

    def __float__(self):   
        """ x.__float__() <==> float(x) """
        pass
    print(float.__float__(2.0)) 2.0转换为小数
        
    def __floordiv__(self, y):   
        """ x.__floordiv__(y) <==> x//y """
        pass
        print(float.__floordiv__(5.0,2.0)) 2.0 整除
        
        def __format__(self, format_spec):   
        """
        float.__format__(format_spec) -> string
        
        Formats the float according to format_spec.
        """
        return ""
        
        

    def __getattribute__(self, name):   
        """ x.__getattribute__(‘name‘) <==> x.name """
        pass
    

    def __getformat__(self, typestr):   
        """
        float.__getformat__(typestr) -> string
        
        You probably don‘t want to use this function.  It exists mainly to be
        used in Python‘s test suite.
        
        typestr must be ‘double‘ or ‘float‘.  This function returns whichever of
        ‘unknown‘, ‘IEEE, big-endian‘ or ‘IEEE, little-endian‘ best describes the
        format of floating point numbers used by the C type named by typestr.
        """
        return ""

    def __getnewargs__(self, *args, **kwargs): # real signature unknown
        pass

    def __ge__(self, y):   
        """ x.__ge__(y) <==> x>=y """
        pass
        大于等于 print(float.__ge__(2.0,1.0)) True

    def __gt__(self, y):   
        """ x.__gt__(y) <==> x>y """
        pass
    大于
        
    def __hash__(self):   
        """ x.__hash__() <==> hash(x) """
        pass
    print(float.__hash__(5.0)) 5 去掉小数
    
    def __init__(self, x):   
        pass
        print(float.__init__(2.0)) 空值

    def __int__(self):   
        """ x.__int__() <==> int(x) """
        pass
        转换为整数print(float.__int__(1.0)) 1
        

    def __le__(self, y):   
        """ x.__le__(y) <==> x<=y """
        pass
        小于等于
        print(float.__le__(1.0,2.0)) True


    def __long__(self):   
        """ x.__long__() <==> long(x) """
        pass
        转换为长整型
        
        

    def __lt__(self, y):   
        """ x.__lt__(y) <==> x<y """
        pass
        小于

    def __mod__(self, y):   
        """ x.__mod__(y) <==> x%y """
        pass
    取余数
        print(float.__mod__(2.0,1.0)) 0.0
    
    def __mul__(self, y):   
        """ x.__mul__(y) <==> x*y """
        pass
    乘
    
        print(float.__mul__(1.0,2.0)) 2.0
    
    def __neg__(self):   
        """ x.__neg__() <==> -x """
        pass
    print(float.__neg__(1.0)) -1.0 转换为负数    
    
    @staticmethod # known case of __new__
    def __new__(S, *more):   
        """ T.__new__(S, ...) -> a new object with type S, a subtype of T """
        pass

    def __ne__(self, y):   
        """ x.__ne__(y) <==> x!=y """
        pass
        是否不相等 print(float.__ne__(1.0,1.0)) False

    def __nonzero__(self):   
        """ x.__nonzero__() <==> x != 0 """
        pass
        是否不等于0
        
    def __pos__(self):   
        """ x.__pos__() <==> +x """
        pass
        

    def __pow__(self, y, z=None):   
        """ x.__pow__(y[, z]) <==> pow(x, y[, z]) """
        pass

    def __radd__(self, y):   
        """ x.__radd__(y) <==> y+x """
        pass
        加

    def __rdivmod__(self, y):   
        """ x.__rdivmod__(y) <==> divmod(y, x) """
        pass
        print(float.__rdivmod__(2.0,1.0))除 取余数 (0.0, 1.0)


    def __rdiv__(self, y):   
        """ x.__rdiv__(y) <==> y/x """
        pass
        除
        

    def __repr__(self):   
        """ x.__repr__() <==> repr(x) """
        pass
        
        

    def __rfloordiv__(self, y):   
        """ x.__rfloordiv__(y) <==> y//x """
        pass
        地板除

    def __rmod__(self, y):   
        """ x.__rmod__(y) <==> y%x """
        pass
        取余数

    def __rmul__(self, y):   
        """ x.__rmul__(y) <==> y*x """
        pass
        乘
        
    def __rpow__(self, x, z=None):   
        """ y.__rpow__(x[, z]) <==> pow(x, y[, z]) """
        pass

    def __rsub__(self, y):   
        """ x.__rsub__(y) <==> y-x """
        pass

        print(float.__rsub__(1.0,2.0)) 1.0减
        
        
    def __rtruediv__(self, y):   
        """ x.__rtruediv__(y) <==> y/x """
        pass
        print(float.__rtruediv__(2.0,1.0)) 0.5 除法
        

    def __setformat__(self, typestr, fmt):   
        """
        float.__setformat__(typestr, fmt) -> None
        
        You probably don‘t want to use this function.  It exists mainly to be
        used in Python‘s test suite.
        
        typestr must be ‘double‘ or ‘float‘.  fmt must be one of ‘unknown‘,
        ‘IEEE, big-endian‘ or ‘IEEE, little-endian‘, and in addition can only be
        one of the latter two if it appears to match the underlying C reality.
        
        Override the automatic determination of C-level floating point type.
        This affects how floats are converted to and from binary strings.
        """
        pass

    def __str__(self):   
        """ x.__str__() <==> str(x) """
        pass
        print(float.__str__(1.0)) 转换为字符
        
    def __sub__(self, y):   
        """ x.__sub__(y) <==> x-y """
        pass
        print(float.__sub__(2.0,1.0)) 1.0 减法

    def __truediv__(self, y):   
        """ x.__truediv__(y) <==> x/y """
        pass
        print(float.__truediv__(3.0,1.5)) 整除
        
    def __trunc__(self, *args, **kwargs): # real signature unknown
        """ Return the Integral closest to x between 0 and x. """
        pass
        

    imag = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the imaginary part of a complex number"""

    real = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """the real part of a complex number"""

 float

float(浮点数)功能详解

标签:

原文地址:http://www.cnblogs.com/dahuige/p/5129784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!