Skip to content

Commit

Permalink
Add some more info to Base.@irrational (#46525)
Browse files Browse the repository at this point in the history
  • Loading branch information
udohjeremiah committed Aug 29, 2022
1 parent 72222d6 commit 6ba623e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ round(x::Irrational, r::RoundingMode) = round(float(x), r)
Define a new `Irrational` value, `sym`, with pre-computed `Float64` value `val`,
and arbitrary-precision definition in terms of `BigFloat`s given by the expression `def`.
An `AssertionError` is thrown when either `big(def) isa BigFloat` or `Float64(val) == Float64(def)`
returns `false`.
# Examples
```jldoctest
julia> Base.@irrational(twoπ, 6.2831853071795864769, 2*big(π))
julia> twoπ
twoπ = 6.2831853071795...
julia> Base.@irrational sqrt2 1.4142135623730950488 √big(2)
julia> sqrt2
sqrt2 = 1.4142135623730...
julia> Base.@irrational sqrt2 1.4142135623730950488 big(2)
ERROR: AssertionError: big($(Expr(:escape, :sqrt2))) isa BigFloat
julia> Base.@irrational sqrt2 1.41421356237309 √big(2)
ERROR: AssertionError: Float64($(Expr(:escape, :sqrt2))) == Float64(big($(Expr(:escape, :sqrt2))))
```
"""
macro irrational(sym, val, def)
esym = esc(sym)
Expand Down

0 comments on commit 6ba623e

Please sign in to comment.