- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.7k
Labels
correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingBugs that are likely to lead to incorrect results in user code without throwingmathsMathematical functionsMathematical functions
Description
prevfloat is implemented by calling nextfloat on the same value but with the iteration count negated:
prevfloat(x::AbstractFloat, d::Integer) = nextfloat(x, -d) julia/base/float.jl#870
For Unsigned iteration counts, this causes underflow and returns unexpected results.
Examples:
prevfloat(1.0, 1)
# 0.9999999999999999        expected result
prevfloat(1.0, 0x01)
# 1.0000000000000566        == nextfloat(1.0, 0xff)
prevfloat(1.0, 0x00000001)
# 1.0000009536743162        == nextfloat(1.0, 0xffffffff)
Metadata
Metadata
Assignees
Labels
correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingBugs that are likely to lead to incorrect results in user code without throwingmathsMathematical functionsMathematical functions