Python Forum
method float.as_integer_ratio() always ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
method float.as_integer_ratio() always ...
#6
This approximate is also given by the Fraction module
>>> from fractions import Fraction as F
>>> y = F(884279719003555,281474976710656)
>>> y.limit_denominator(100000000)
Fraction(245850922, 78256779)
The purpose of float.as_integer_ratio() is to give an integer ratio that is exactly equal to the real number stored in memory (which is not pi but an approximation of pi). It is a different problem from approximating pi with shorter fractions. The IEEE754 format indeed implies that the actual denominator is a power of two.

Note that for most floating numbers, you cannot expect a significant reduction of the size of the integers by doing this because the global number of bits needed to distinguish these numbers is fixed.
Reply


Messages In This Thread
RE: method float.as_integer_ratio() always ... - by Gribouillis - Jul-02-2019, 09:57 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020