Skip to content

Underflow in prevfloat with Unsigned iteration count #59661

@enbyd

Description

@enbyd

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

No one assigned

    Labels

    correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwingmathsMathematical functions

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions