Skip to content

Commit f052e8f

Browse files
committed
handle conversion of NAN, oo
1 parent 32b15fe commit f052e8f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymEngine"
22
uuid = "123dc426-2d89-5057-bbad-38513e3affd8"
3-
version = "0.11.0"
3+
version = "0.11.1"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

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)