added reference to float.as_integer_ratio
This commit is contained in:
parent
32f23dad4a
commit
72fbb846df
14
ex_01_03.py
14
ex_01_03.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
import cmath
|
||||||
|
|
||||||
def bailey_borwein_plouffe_pi(n):
|
def bailey_borwein_plouffe_pi(n):
|
||||||
"""
|
"""
|
||||||
|
@ -26,3 +27,16 @@ if( __name__ == "__main__"):
|
||||||
# Because ``a/b`` **cannot** return the same object as ``math.pi``,
|
# Because ``a/b`` **cannot** return the same object as ``math.pi``,
|
||||||
# the latter was created when the module ``math`` was initialized,
|
# the latter was created when the module ``math`` was initialized,
|
||||||
# this will **always** evaluate to False.
|
# this will **always** evaluate to False.
|
||||||
|
|
||||||
|
# As it turns out there is also the ``float.as_integer_ratio``.
|
||||||
|
# Now I kind of assume that this exercise aims torward this crap.
|
||||||
|
# You can use this method to construct two integers that are a
|
||||||
|
# fractional representation of the float.
|
||||||
|
#
|
||||||
|
# I doubt very much that there is a use case for this crap.
|
||||||
|
# There is the built-in module ``decimal`` that provides
|
||||||
|
# a proper way of dealing with floating point arithmetics,
|
||||||
|
# rounding and precision.
|
||||||
|
|
||||||
|
a,b = math.pi.as_integer_ratio()
|
||||||
|
assert a/b == math.pi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user