Skip to content

Commit ab942f2

Browse files
fix: fix handling of rationals in Div
1 parent 407b298 commit ab942f2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/types.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,8 @@ and the rational/integer factor (or `NaN` otherwise).
11891189
function ratcoeff(x)
11901190
if iscall(x) && operation(x) === (*)
11911191
ratcoeff(get_mul_coefficient(x))
1192+
elseif safe_isinteger(x)
1193+
(true, Int(x))
11921194
elseif x isa Rat
11931195
(true, x)
11941196
else
@@ -1202,6 +1204,12 @@ end
12021204
Simplify the coefficients of `n` and `d` (numerator and denominator).
12031205
"""
12041206
function simplify_coefficients(n, d)
1207+
if safe_isinteger(n)
1208+
n = Int(n)
1209+
end
1210+
if safe_isinteger(d)
1211+
d = Int(d)
1212+
end
12051213
nrat, nc = ratcoeff(n)
12061214
drat, dc = ratcoeff(d)
12071215
nrat && drat || return n, d

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Base: ImmutableDict
22

33
safe_isinteger(x::Number) = isinteger(x) && abs(x) < typemax(Int)
4+
safe_isinteger(x) = false
45

56
pow(x,y) = y==0 ? 1 : y<0 ? inv(x)^(-y) : x^y
67
pow(x::BasicSymbolic,y) = y==0 ? 1 : Base.:^(x,y)

0 commit comments

Comments
 (0)