@@ -34,6 +34,8 @@ import Base: reinterpret, zero, one, abs, sign, ==, <, <=, +, -, /, *, div,
3434 typemin, typemax, realmin, realmax, print, show, string, convert,
3535 promote_rule, min, max, trunc, round, floor, ceil, eps, float, widemul
3636
37+ import Base. Checked: checked_mul
38+
3739const IEEEFloat = Union{Float16, Float32, Float64}
3840
3941for fn in [:trunc , :floor , :ceil ]
@@ -143,6 +145,21 @@ function /{T, f}(x::FD{T, f}, y::FD{T, f})
143145 reinterpret (FD{T, f}, quotient * powt + round (T, remainder / y. i * powt))
144146end
145147
148+ # these functions are needed to avoid InexactError when converting from the integer type
149+ function / {T, f}(x:: Integer , y:: FD{T, f} )
150+ powt = T (10 )^ f
151+ xi, yi = checked_mul (x, powt), y. i
152+ quotient, remainder = divrem (xi, yi)
153+ reinterpret (FD{T, f}, quotient * powt + round (T, remainder / yi * powt))
154+ end
155+
156+ function / {T, f}(x:: FD{T, f} , y:: Integer )
157+ powt = T (10 )^ f
158+ xi, yi = x. i, checked_mul (y, powt)
159+ quotient, remainder = divrem (xi, yi)
160+ reinterpret (FD{T, f}, quotient * powt + round (T, remainder / yi * powt))
161+ end
162+
146163# integerification
147164trunc {T, f} (x:: FD{T, f} ) = FD {T, f} (div (x. i, T (10 )^ f))
148165floor {T, f} (x:: FD{T, f} ) = FD {T, f} (fld (x. i, T (10 )^ f))
0 commit comments