Float Data Type

Source: Internet
Author: User

Float Data Type

To learn a language, you must lay a solid foundation. The previous knowledge may be boring, but it is very important to lay a solid foundation for us, be sure to master basic common operations for int, float, long, String, list, tuples, sets, dictionaries, functions, and classes.

Next, let's take a look at the common operations of float data types, and the differences between float and int:

1. as_integer_ratio ()

Def as_integer_ratio (self): # real signature unknown; restored from _ doc __
"""
Float. as_integer_ratio ()-> (int, int)

Returns the smallest integer of a score. It is displayed in the form of a tuple.

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

2. conjugate (self, * args, ** kwargs)

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

"Conjugate () returns the complex number of the conjugate, which we learned in high school """
Pass

3. fromhex (self, * args, ** kwargs)

Def fromhex (self, string): # real signature unknown; restored from _ doc __
"""
Float. fromhex (string)-> float

Create a floating-point number from a hexadecimal string.
>>> Float. fromhex ('0x1. ffffp10 ')
2047.984375
>>> Float. fromhex ('-0x1p-1074 ')
-5e-324
"""
Return 0.0

4. hex (self)

Def hex (self): # real signature unknown; restored from _ doc __
"""
Float. hex ()-> string

Return a hexadecimal representation of a floating-point number.
>>> (-0.1). hex ()
'-0x1. 9999999999ap-4'
>>> 3.14159.hex ()
'0x1. 921f9f01b866ep + 1'
"""
Return ""

5. is_integer (self, * args, ** kwargs)

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

"Determining whether a floating point data is an integer (that is, the fractional part is zero )"""
Pass

Example:

>>> A = 3.0
>>> B = 5.9
>>> A. is_integer ()
True
>>> B. is_integer ()
False
We have defined two numbers 3.0 and 5.9, of which 3.0 meets is_integer, and 5.9 does not meet the returned Boolean value False.

6. _ abs _ (self, * args, ** kwargs)

Def _ abs _ (self, * args, ** kwargs): # real signature unknown
"" Abs (self )"""

"Returns the absolute value of A number """
Pass

Example:

>>> A =-3.59
>>> B =-3
>>> A. _ abs __()
3.59
>>> B. _ abs __()
3

  7. _ add _ (self, * args, ** kwargs)

Def _ add _ (self, * args, ** kwargs): # real signature unknown
"" Return self + value ."""

"Add two numbers """
Pass

8. _ setformat _ (self, typestr, fmt)

Def _ setformat _ (self, typestr, fmt): # real signature unknown; restored from _ doc __
"""
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

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.