Skip to content

Commit bd2ac09

Browse files
JeffBezansonKristofferC
authored andcommitted
make fallback signed and unsigned functions unchecked (as documented) (#34287)
(cherry picked from commit 37275c3)
1 parent f03279d commit bd2ac09

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

base/int.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ julia> signed(unsigned(-2))
155155
-2
156156
```
157157
"""
158-
unsigned(x) = convert(Unsigned, x)
158+
unsigned(x) = x % typeof(convert(Unsigned, zero(x)))
159159
unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x)
160160

161161
"""
@@ -164,7 +164,7 @@ unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x)
164164
Convert a number to a signed integer. If the argument is unsigned, it is reinterpreted as
165165
signed without checking for overflow.
166166
"""
167-
signed(x) = convert(Signed, x)
167+
signed(x) = x % typeof(convert(Signed, zero(x)))
168168
signed(x::BitUnsigned) = reinterpret(typeof(convert(Signed, zero(x))), x)
169169

170170
div(x::BitSigned, y::Unsigned) = flipsign(signed(div(unsigned(abs(x)), y)), x)

0 commit comments

Comments
 (0)