Skip to content

Commit 21f8f55

Browse files
authored
Merge pull request #271 from jverzani/evalf
handle conversion of NAN, oo
2 parents 174486f + 3ce02ae commit 21f8f55

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/numerics.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Base: trunc, ceil, floor, round
44

55

66
function evalf(b::Basic, bits::Integer=53, real::Bool=false)
7+
!isfinite(b) && return b
78
c = Basic()
89
bits > 53 && real && (have_mpfr || throw(ArgumentError("libsymengine has to be compiled with MPFR for this feature")))
910
bits > 53 && !real && (have_mpc || throw(ArgumentError("libsymengine has to be compiled with MPC for this feature")))
@@ -133,7 +134,11 @@ N(b::BasicType{Val{:Rational}}) = Rational(N(numerator(b)), N(denominator(b))) #
133134
N(b::BasicType{Val{:RealDouble}}) = convert(Cdouble, b)
134135
N(b::BasicType{Val{:RealMPFR}}) = convert(BigFloat, b)
135136
N(b::BasicType{Val{:NaN}}) = NaN
136-
N(b::BasicType{Val{:Infty}}) = (string(b) == "-inf") ? -Inf : Inf
137+
function N(b::BasicType{Val{:Infty}})
138+
b == oo && return Inf
139+
b == -oo && return -Inf
140+
b == zoo && return Complex(Inf, Inf)
141+
end
137142

138143
## Mapping of SymEngine Constants into julia values
139144
constant_map = Dict("pi" => π, "eulergamma" => γ, "exp(1)" => e, "catalan" => catalan,

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ z,flt, rat, ima, cplx = btypes = [Basic(1), Basic(1.23), Basic(3//5), Basic(2im)
207207
@test convert(Rational{Int}, rat) == 3//5
208208
@test convert(Complex{Int}, ima) == 2im
209209
@test convert(Complex{Int}, cplx) == 1 + 2im
210+
@test isinf(convert(Float64, oo))
211+
@test isnan(convert(Float64, NAN))
210212

211213
@test_throws InexactError convert(Int, flt)
212214
@test_throws InexactError convert(Int, rat)

0 commit comments

Comments
 (0)