Python Forum
smallest float that can increment a given value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
smallest float that can increment a given value
#2
Not exactly, but the math module provides the function nextafter(x,y) that returns the next floating-point value after x towards y.

>>> math.nextafter(12,0) # The next float towards 0.
11.999999999999998
>>> 12-math.nextafter(12,0)
1.7763568394002505e-15
>>> _.hex()
'0x1.0000000000000p-49'
>>> 
Naming isn't really consistent.

The decimal provides context methods called next_plus, 'next_minus, and next_towards`.

gmpy2 uses the names next_above and next_below.
Skaperen and DeaD_EyE like this post
Reply


Messages In This Thread
RE: smallest float that can increment a given value - by casevh - Dec-11-2021, 05:32 AM

Forum Jump:

User Panel Messages

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