Skip to content

Incorrect conversion to unisigned integer #51063

Closed
@LilithHafner

Description

@LilithHafner
julia> convert(UInt32, 4.2949673f9)
0xffffffff

4.2949673f9 is one greater than the maximum value of a UInt32 (4.2949673f9 == typemax(UInt32)+1) so an inexact error should be thrown here:

function (::Type{$Ti})(x::$Tf)
    if ($(Tf(typemin(Ti))) <= x <= $(Tf(typemax(Ti)))) && isinteger(x)
        return unsafe_trunc($Ti,x)
    else
        throw(InexactError($(Expr(:quote,Ti.name.name)), $Ti, x))
    end
end

However, the comparison that happens is 4.2949673f9 <= Float32(typemax(UInt32)) which is true even though 4.2949673f9 > typemax(UInt32).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviormathsMathematical functions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions