Comments (3)
The promotion rules for div
/rem
/mod
are similar to powers, and the promotion rules for it also aren't in the docstring.
julia> 0x11 + 1, 0x11 * 1, 0x11 ^ 1, 0x11 ÷ 1, 0x11 % 1
(18, 17, 0x11, 0x0000000000000011, 0x0000000000000000)
Though also inconsistent that div
and rem
move to UInt64
while ^
sticks to the bit width of the first argument.
from julia.
wat
julia> 0xFF ÷ Int8(-1)
0x01
Since Julia doesn't widen results of operations beyond their input argument types, the consistent option would be for unsigned dividends with negative divisors to throw a DivideError
, just like when typemin(Int) ÷ -1
does. Integer division in Julia is documented to be safe from overflow, so this should probably be fixed.
IMO then integer division result should just be the type of the dividend, rather than the current signedness of the dividend and largest width of either argument.
For rem
, can use the same rule, with the exception that there's no need to throw an error on "overflow" (following the pattern of typemin(Int) % -1
not erroring, and all results are positive.
For mod
, the promotion rule should possibly be the typical promotion widening, because a result has to fit within the range of the divisor's type to be fully represented, but probably don't want it to be any narrower than the dividend.
from julia.
Out of curiosity I looked at what C# does. It's also messy, but does prevent overflow.
In C#, all integer division/remainder results are widened to contain all valid results of the input types (e.g. UInt32 ÷ Int8 = Int64), with a minimum of Int32. Only if both are unsigned and at least one argument is 32-bit or larger will it return an unsigned result. If it can't widen further, the operation is not valid.
from julia.
Related Issues (20)
- Performance regressions in linear algebra benchmarks with Hermitian and Triangular matrices
- Performance regressions in BaseBenchmarks due to #54647 (Cleanup `MemoryRef`) HOT 3
- observed failure of TestPkg thread test
- race condition in waitany test
- Regression in threads tests on FreeBSD
- Operations on `views` much slower when indices are `start:1:stop` HOT 7
- [1.11+] jl_array_t no longer contains elsz HOT 1
- Unreachable reached
- `mkpath` does not stably return the original path
- Deserialization in a Module() HOT 2
- `last(::Tuple{})` throws `BoundsError` HOT 5
- document `FieldError`
- peek docstring has a disconnect HOT 2
- Precompiling and FunctionWrappers lead to extra runtime allocations HOT 4
- Matrix `exp` and `log` are not inverse of each other HOT 12
- recursive type parameter constraints HOT 3
- [CI] Intermittent failure in `Profile` on aarch64-linux-gnu HOT 1
- @time always shows reports compilation times while SnoopCompile does not HOT 1
- Problem with `similar` called for view-types such as `SubArray`, `ReshapedArray` or `ReinterpretArray` HOT 1
- 5% regression in some Inference benchmarks due to #51149 (Set temporary env whenever Julia is started with `--project=@temp`) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.