Skip to content

Commit 7c20816

Browse files
RohitRathore1LilithHafner
authored andcommitted
BigFloat: fix inconsistency in allowed precision (JuliaLang#40872)
Fixes JuliaLang#40538
1 parent b8c2461 commit 7c20816

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

base/mpfr.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ Set the precision (in bits) to be used for `T` arithmetic.
815815
setting.
816816
"""
817817
function setprecision(::Type{BigFloat}, precision::Integer)
818-
if precision < 2
819-
throw(DomainError(precision, "`precision` cannot be less than 2."))
818+
if precision < 1
819+
throw(DomainError(precision, "`precision` cannot be less than 1."))
820820
end
821821
DEFAULT_PRECISION[] = precision
822822
return precision

test/mpfr.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ end
475475
@test precision(z) == 240
476476
x = BigFloat(12)
477477
@test precision(x) == old_precision
478-
@test_throws DomainError setprecision(1)
478+
@test precision(setprecision(1) do; BigFloat(23); end) == 1 # minimum-precision
479+
@test_throws DomainError setprecision(0)
479480
@test_throws DomainError BigFloat(1, precision = 0)
480481
@test_throws DomainError BigFloat(big(1.1), precision = 0)
481482
@test_throws DomainError BigFloat(2.5, precision = -900)

0 commit comments

Comments
 (0)