From 0f77de44b6b7d5b27d4950fecc05eedb5cd47632 Mon Sep 17 00:00:00 2001
From: Klaus Crusius
Date: Thu, 2 May 2024 02:54:41 +0200
Subject: [PATCH] mpfr_overflow_typo (#54284)
That looks like an editing error.
---
base/mpfr.jl | 3 ++-
test/mpfr.jl | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/base/mpfr.jl b/base/mpfr.jl
index 788ecf4f99790..e61f115b35093 100644
--- a/base/mpfr.jl
+++ b/base/mpfr.jl
@@ -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
diff --git a/test/mpfr.jl b/test/mpfr.jl
index a0dd15d97f70c..9a9698ba72c2c 100644
--- a/test/mpfr.jl
+++ b/test/mpfr.jl
@@ -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