@@ -3,8 +3,8 @@ module FixedPointNumbers
33import Base: == , < , <= , - , + , * , / , ~ , isapprox,
44 convert, promote_rule, show, isinteger, abs, decompose,
55 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,
88 div, fld, rem, mod, mod1, fld1, min, max, minmax,
99 rand, length
1010
@@ -69,6 +69,14 @@ function (::Type{Ti})(x::FixedPoint) where {Ti <: Integer}
6969end
7070Base. Rational {Ti} (x:: FixedPoint ) where {Ti <: Integer } = Rational {Ti} (Rational (x))
7171
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+
7280"""
7381 isapprox(x::FixedPoint, y::FixedPoint; rtol=0, atol=max(eps(x), eps(y)))
7482
0 commit comments