Skip to content

Commit

Permalink
docs: warn against @big_str not obeying rounding mode or precision (#…
Browse files Browse the repository at this point in the history
…50800)

One of the big pitfalls when using `BigFloat`.
  • Loading branch information
nsajko committed Aug 20, 2023
1 parent ce3f97c commit 96e5b62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,15 @@ julia> big"_"
ERROR: ArgumentError: invalid number format _ for BigInt or BigFloat
[...]
```
!!! warning
Using `@big_str` for constructing [`BigFloat`](@ref) values may not result
in the behavior that might be naively expected: as a macro, `@big_str`
obeys the global precision ([`setprecision`](@ref)) and rounding mode
([`setrounding`](@ref)) settings as they are at *load time*. Thus, a
function like `() -> precision(big"0.3")` returns a constant whose value
depends on the value of the precision at the point when the function is
defined, **not** at the precision at the time when the function is called.
"""
macro big_str(s)
message = "invalid number format $s for BigInt or BigFloat"
Expand Down
7 changes: 7 additions & 0 deletions doc/src/manual/integers-and-floating-point-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,13 @@ julia> setprecision(40) do
1.1000000000004
```

!!! warning
The relation between [`setprecision`](@ref) or [`setrounding`](@ref) and
[`@big_str`](@ref), the macro used for `big` string literals (such as
`big"0.3"`), might not be intuitive, as a consequence of the fact that
`@big_str` is a macro. See the [`@big_str`](@ref) documentation for
details.

## [Numeric Literal Coefficients](@id man-numeric-literal-coefficients)

To make common numeric formulae and expressions clearer, Julia allows variables to be immediately
Expand Down

4 comments on commit 96e5b62

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Please sign in to comment.