You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like this is because Float16(typemin(Int)) is -Inf16 and the check in trunc is inclusive on the lower bound. Compare that to Float32 for which Float32(typemin(Int)) > -Inf32. In fact, this is touched on in a comment in the code:
This assumes that Tf(typemin(Ti)) > -Inf, which is true for these types, but not for Float16 or larger integer types.
Perhaps that assumption should be explicit as part of the condition? Like
--- a/base/float.jl+++ b/base/float.jl@@ -953,7 +953,7 @@ for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UIn
# these types, but not for `Float16` or larger integer types.
@eval begin
function trunc(::Type{$Ti},x::$Tf)
- if $(Tf(typemin(Ti))) <= x < $(Tf(typemax(Ti)))+ if isfinite(x) && $(Tf(typemin(Ti))) <= x < $(Tf(typemax(Ti)))
return unsafe_trunc($Ti,x)
else
throw(InexactError(:trunc, $Ti, x))
The text was updated successfully, but these errors were encountered: