@@ -3,8 +3,8 @@ module FixedPointNumbers
3
3
import Base: == , < , <= , - , + , * , / , ~ , isapprox,
4
4
convert, promote_rule, show, isinteger, abs, decompose,
5
5
isnan, isinf, isfinite,
6
- zero, oneunit, one, typemin, typemax, floatmin, floatmax, eps, sizeof, reinterpret,
7
- float, trunc, round, floor, ceil, bswap,
6
+ zero, oneunit, one, typemin, typemax, floatmin, floatmax, eps, reinterpret,
7
+ big, rationalize, float, trunc, round, floor, ceil, bswap,
8
8
div, fld, rem, mod, mod1, fld1, min, max, minmax,
9
9
rand, length
10
10
@@ -69,6 +69,14 @@ function (::Type{Ti})(x::FixedPoint) where {Ti <: Integer}
69
69
end
70
70
Base. Rational {Ti} (x:: FixedPoint ) where {Ti <: Integer } = Rational {Ti} (Rational (x))
71
71
72
+ big (:: Type{<:FixedPoint} ) = BigFloat
73
+ big (x:: FixedPoint ) = convert (BigFloat, x)
74
+
75
+ rationalize (x:: FixedPoint ; tol:: Real = eps (x)) = rationalize (Int, x, tol= tol)
76
+ function rationalize (:: Type{Ti} , x:: FixedPoint ; tol:: Real = eps (x)) where Ti <: Integer
77
+ tol <= eps (x) ? Rational {Ti} (x) : rationalize (Ti, float (x), tol)
78
+ end
79
+
72
80
"""
73
81
isapprox(x::FixedPoint, y::FixedPoint; rtol=0, atol=max(eps(x), eps(y)))
74
82
0 commit comments