Skip to content

Commit

Permalink
mpfr_overflow_typo (#54284)
Browse files Browse the repository at this point in the history
That looks like an editing error.
  • Loading branch information
KlausC authored May 2, 2024
1 parent 57b9b59 commit 0f77de4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,8 @@ end
# flags
clear_flags() = ccall((:mpfr_clear_flags, libmpfr), Cvoid, ())
had_underflow() = ccall((:mpfr_underflow_p, libmpfr), Cint, ()) != 0
had_overflow() = ccall((:mpfr_underflow_p, libmpfr), Cint, ()) != 0
had_overflow() = ccall((:mpfr_overflow_p, libmpfr), Cint, ()) != 0
had_divbyzero() = ccall((:mpfr_divby0_p, libmpfr), Cint, ()) != 0
had_nan() = ccall((:mpfr_nanflag_p, libmpfr), Cint, ()) != 0
had_inexact_exception() = ccall((:mpfr_inexflag_p, libmpfr), Cint, ()) != 0
had_range_exception() = ccall((:mpfr_erangeflag_p, libmpfr), Cint, ()) != 0
Expand Down
42 changes: 42 additions & 0 deletions test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,45 @@ end
@test Float16(bf) == Float16(2.0e-7)
end
end

# PR #54284
import Base.MPFR: clear_flags, had_underflow, had_overflow, had_divbyzero,
had_nan, had_inexact_exception, had_range_exception

function all_flags_54284()
(
had_underflow(),
had_overflow(),
had_divbyzero(),
had_nan(),
had_inexact_exception(),
had_range_exception(),
)
end
@testset "MPFR flags" begin
let x, a = floatmin(BigFloat), b = floatmax(BigFloat), c = zero(BigFloat)
clear_flags()
@test !any(all_flags_54284())

x = a - a # normal
@test all_flags_54284() == (false, false, false, false, false, false)
x = 1 / c # had_divbyzero
@test all_flags_54284() == (false, false, true, false, false, false)
clear_flags()
x = nextfloat(a) - a # underflow
@test all_flags_54284() == (true, false, false, false, true, false)
clear_flags()
x = 1 / a # overflow
@test all_flags_54284() == (false, true, false, false, true, false)
clear_flags()
x = c / c # nan
@test all_flags_54284() == (false, false, false, true, false, false)
clear_flags()
x = prevfloat(BigFloat(1.0)) * 100 # inexact
@test all_flags_54284() == (false, false, false, false, true, false)
clear_flags()
try convert(Int, b); catch; end # range exception
@test all_flags_54284() == (false, false, false, false, false, true)
clear_flags()
end
end

0 comments on commit 0f77de4

Please sign in to comment.