Skip to content

Commit

Permalink
Merge pull request #5036 from simonbyrne/bigrealminmax
Browse files Browse the repository at this point in the history
add realmin realmax for BigFloat
  • Loading branch information
JeffBezanson committed Dec 7, 2013
2 parents 9d63f84 + 132642f commit d952dae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import
gamma, lgamma, digamma, erf, erfc, zeta, log1p, airyai, iceil, ifloor,
itrunc, eps, signbit, sin, cos, tan, sec, csc, cot, acos, asin, atan,
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2,
serialize, deserialize, inf, nan, hash, cbrt, typemax, typemin
serialize, deserialize, inf, nan, hash, cbrt, typemax, typemin,
realmin, realmax

import Base.Math.lgamma_r

Expand Down Expand Up @@ -687,6 +688,9 @@ end

eps(::Type{BigFloat}) = nextfloat(BigFloat(1)) - BigFloat(1)

realmin(::Type{BigFloat}) = nextfloat(zero(BigFloat))
realmax(::Type{BigFloat}) = prevfloat(inf(BigFloat))

function with_bigfloat_precision(f::Function, precision::Integer)
old_precision = get_bigfloat_precision()
set_bigfloat_precision(precision)
Expand Down
8 changes: 8 additions & 0 deletions test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ end
x = eps(BigFloat)
@test BigFloat(1) + x == BigFloat(1) + prevfloat(x)

# realmin/realmax
x = realmin(BigFloat)
@test x > 0
@test prevfloat(x) == 0
x = realmax(BigFloat)
@test !isinf(x)
@test isinf(nextfloat(x))

# factorial
with_bigfloat_precision(256) do
x = BigFloat(42)
Expand Down

0 comments on commit d952dae

Please sign in to comment.