Skip to content

Commit a1b1612

Browse files
committed
restore fallback 3-arg setprecision method
fixes #55899
1 parent b61664e commit a1b1612

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

base/mpfr.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,25 @@ Often used as `setprecision(T, precision) do ... end`
11831183
Note: `nextfloat()`, `prevfloat()` do not use the precision mentioned by
11841184
`setprecision`.
11851185
1186+
!!! warning
1187+
There is a fallback implementation of this method that calls `precision`
1188+
and `setprecision`, but it should no longer be relied on. Instead, you
1189+
should define the 3-argument form directly in a way that uses `ScopedValue`,
1190+
or recommend that callers use `ScopedValue` and `@with` themselves.
1191+
11861192
!!! compat "Julia 1.8"
11871193
The `base` keyword requires at least Julia 1.8.
11881194
"""
1195+
function setprecision(f::Function, ::Type{T}, prec::Integer; kws...) where T
1196+
old_prec = precision(T)
1197+
setprecision(T, prec; kws...)
1198+
try
1199+
return f()
1200+
finally
1201+
setprecision(T, old_prec)
1202+
end
1203+
end
1204+
11891205
function setprecision(f::Function, ::Type{BigFloat}, prec::Integer; base::Integer=2)
11901206
Base.ScopedValues.@with(CURRENT_PRECISION => _convert_precision_from_base(prec, base), f())
11911207
end

0 commit comments

Comments
 (0)