JuliaLang/julia

Document promotion behavior of `div` and `divrem` for `(::Unsigned, ::Signed)`

Open

#57.855 geöffnet am 21. März 2025

Auf GitHub ansehen
 (8 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Julia (5.773 Forks)batch import
docshelp wanted

Repository-Metriken

Stars
 (48.709 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 23T 11h) (145 gemergte PRs in 30 T)

Beschreibung

Currently we have

julia> div(UInt(1), -1)
0xffffffffffffffff

This happens because we are returning the promote_type, but violates both common sense, and the documentation which states "Generally equivalent to a mathematical operation x/y without a fractional part".

As such, I propose that we instead make the return type of div(x,y) be ifelse(isa(y, Signed), signed(promote_type(x,y)), promote_type(x,y)). This would obviously be slightly breaking, but I think it qualifies as a bugfix.

We also would want to make similar changes for divrem, fld, cld since they all have the same problem.

Contributor Guide