Skip to content

Commit

Permalink
add tests for BigFloat constructor, nextfloat and prevfloat
Browse files Browse the repository at this point in the history
  • Loading branch information
narendrakpatel committed Mar 10, 2019
1 parent bdae29c commit de29df0
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion test/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ import Base.MPFR
setprecision(prec) do
@test precision(xs[end]) != prec
for x in xs
@test precision(BigFloat(x)) == prec
@test precision(BigFloat(x; precision=prec ÷ 2)) == prec ÷ 2
end
@test precision(BigFloat(12.12)) == prec
end
end

# test for new BigFloat constructor
a = BigFloat(pi, precision=100)
b = BigFloat(a)
@test a === b
b = BigFloat(a, new=true)
@test a !== b && a == b
b = BigFloat(a, precision=128)
@test a !== b && a == b && precision(b) == 128
end
@testset "basic arithmetic" begin
tol = 1e-12
Expand Down Expand Up @@ -444,8 +453,23 @@ end
@test x == y
nextfloat(y)
@test x == y
z = BigFloat(y, new=true)
nextfloat!(z)
@test z != y && z == nextfloat(y)
y = BigFloat(x)
@test x == y
prevfloat(y)
@test x == y
z = BigFloat(y, new=true)
prevfloat!(z)
@test z != y && z == prevfloat(y)
x = BigFloat(12.12)
@test nextfloat(x, 0) !== x && nextfloat(x, 0) == x
@test nextfloat(x, 1) == nextfloat(x)
@test prevfloat(x, 0) !== x && prevfloat(x, 0) == x
@test prevfloat(x, 1) == prevfloat(x)
@test nextfloat(x, -1) == prevfloat(x, 1)
@test prevfloat(x, -1) == nextfloat(x, 1)
setprecision(53) do
x = BigFloat(12.12)
@test BigFloat(nextfloat(12.12)) == nextfloat(x)
Expand Down

0 comments on commit de29df0

Please sign in to comment.