Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpfr_overflow_typo #54284

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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