Skip to content

Commit 032dbe3

Browse files
authored
fix #34180, check domain of precision in BigFloat ctor (#34204)
1 parent 4c67921 commit 032dbe3

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/mpfr.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mutable struct BigFloat <: AbstractFloat
109109
end
110110

111111
function BigFloat(; precision::Integer=DEFAULT_PRECISION[])
112+
precision < 1 && throw(DomainError(precision, "`precision` cannot be less than 1."))
112113
nb = ccall((:mpfr_custom_get_size,:libmpfr), Csize_t, (Clong,), precision)
113114
nb = (nb + Core.sizeof(Limb) - 1) ÷ Core.sizeof(Limb) # align to number of Limb allocations required for this
114115
#d = Vector{Limb}(undef, nb)

test/mpfr.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ end
487487
x = BigFloat(12)
488488
@test precision(x) == old_precision
489489
@test_throws DomainError setprecision(1)
490+
@test_throws DomainError BigFloat(1, precision = 0)
491+
@test_throws DomainError BigFloat(big(1.1), precision = 0)
492+
@test_throws DomainError BigFloat(2.5, precision = -900)
490493
# issue 15659
491494
@test (setprecision(53) do; big(1/3); end) < 1//3
492495
end

0 commit comments

Comments
 (0)