Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Multi-threading changes
the first time it is called, and then always return the same result value of type `T`
every subsequent time afterwards. There are also `OncePerThread{T}` and `OncePerTask{T}` types for
similar usage with threads or tasks ([#55793]).
* `setprecision` utilizes `ScopedValue` for enhancing thread safety when setting precision levels.
This change allows for safer precision adjustments in multi-threaded environments. ([#51362])

Build system changes
--------------------
Expand Down
17 changes: 12 additions & 5 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1050,15 +1050,22 @@ _precision_with_base_2(::Type{BigFloat}) =
"""
setprecision([T=BigFloat,] precision::Int; base=2)

Set the precision (in bits, by default) to be used for `T` arithmetic.
Set the global precision (in bits, by default) to be used for `T` arithmetic.
If `base` is specified, then the precision is the minimum required to give
at least `precision` digits in the given `base`.

!!! warning
Example:
```julia
setprecision(256)
```

!!! note
Temporarily sets the precision for BigFloat operations to `precision` bits within the
scope of function `f`. This method is thread-safe due to the use of ScopedValue, ensuring
that precision settings do not interfere across threads.

This function is not thread-safe. It will affect code running on all threads, but
its behavior is undefined if called concurrently with computations that use the
setting.
!!! compat "Julia 1.12"
Thread safety via ScopedValue is guaranteed starting with Julia 1.12.

!!! compat "Julia 1.8"
The `base` keyword requires at least Julia 1.8.
Expand Down