-
Notifications
You must be signed in to change notification settings - Fork 32
Closed
Description
convert(Fixed{Int8, 7}, x) seems to happily round to the nearest representable value for most values of x, but throws an InexactError for x=0.999. AFAICT it throws the error when the value would get rounded up to 1.0, but 1.0 can't be represented. Is this expected behavior? I would expect that in this case it would act the same as convert(Fixed{Int8, 7}, 1.0), which overflows to -1.0.
julia> convert(Fixed{Int8, 7}, 0.8)
FixedPointNumbers.Fixed{Int8,7}(0.797)
julia> convert(Fixed{Int8, 7}, 0.9)
FixedPointNumbers.Fixed{Int8,7}(0.898)
julia> convert(Fixed{Int8, 7}, 0.999)
ERROR: InexactError()
in trunc at float.jl:357
in convert at /Users/srussell/.julia/v0.4/FixedPointNumbers/src/fixed.jl:34
julia> convert(Fixed{Int8, 7}, 1.0)
FixedPointNumbers.Fixed{Int8,7}(-1.0)
should convert accept values that can't be exactly represented? My understanding was that normally convert(T, x) is supposed to preserve information and thrown an error if the value can't be represented, and round(T, x) is supposed to be used to round to the nearest representable number, but I don't think that's explicitly said, so I could be wrong there.
Metadata
Metadata
Assignees
Labels
No labels