Skip to content

Commit b24c5ca

Browse files
committed
Update base/rational.jl
1 parent e4d8979 commit b24c5ca

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

base/rational.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ function (::Type{T})(x::Rational{S}) where T<:AbstractFloat where S
145145
P = promote_type(T,S)
146146
convert(T, convert(P,x.num)/convert(P,x.den))::T
147147
end
148-
Float16(x::Rational{<:Union{Int16,Int32,Int64,Int128,UInt16,UInt32,UInt64,UInt128}}) =
149-
Float16(Float32(x)) # avoid spurious overflow (#52394)
148+
# avoid spurious overflow (#52394). (Needed for UInt16 or larger;
149+
# we also include Int16 for consistency of accuracy.)
150+
Float16(x::Rational{<:Union{Int16,Int32,Int64,UInt16,UInt32,UInt64}}) =
151+
Float16(Float32(x))
152+
Float16(x::Rational{<:Union{Int128,UInt128}}) =
153+
Float16(Float64(x)) # UInt128 overflows Float32, include Int128 for consistency
150154

151155
function Rational{T}(x::AbstractFloat) where T<:Integer
152156
r = rationalize(T, x, tol=0)

0 commit comments

Comments
 (0)