File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -1183,9 +1183,25 @@ Often used as `setprecision(T, precision) do ... end`
11831183Note: `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+
11891205function setprecision (f:: Function , :: Type{BigFloat} , prec:: Integer ; base:: Integer = 2 )
11901206 Base. ScopedValues. @with (CURRENT_PRECISION => _convert_precision_from_base (prec, base), f ())
11911207end
You can’t perform that action at this time.
0 commit comments