A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308

mw mingwu at gmail.com
Thu Aug 13 23:07:23 UTC 2020


On Thursday, 13 August 2020 at 22:07:11 UTC, H. S. Teoh wrote:
> Then again, a lot of things are needlessly convoluted in Java, 
> so it's not saying very much. :-P

Some of the D's competitors:

C#
----------------------------------------------------------------------------
using System;
class test{
   public static void Main(string[] args) {
     long a = -5000;
     ulong b = 2;
     long c = a / b; // Operator '/' is ambiguous on operands of 
type 'long' and 'ulong'
   }
}
----------------------------------------------------------------------------
$ mcs div.cs
div.cs(6,14): error CS0019: Operator `/' cannot be applied to 
operands of type `long' and `ulong'
Compilation failed: 1 error(s), 0 warnings


Rust:
----------------------------------------------------------------------------
fn main() {
   let a: i64 = -5000;
   let b: u64 = 2;
   let c: i64 = a / b;
}
----------------------------------------------------------------------------
$ rustc  div.rs
error[E0308]: mismatched types
  --> div.rs:4:20
   |
4 |   let c: i64 = a / b;
   |                    ^ expected `i64`, found `u64`

error[E0277]: cannot divide `i64` by `u64`
  --> div.rs:4:18
   |
4 |   let c: i64 = a / b;
   |                  ^ no implementation for `i64 / u64`
   |
   = help: the trait `std::ops::Div<u64>` is not implemented for 
`i64`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.



More information about the Digitalmars-d mailing list