www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - cast double to long for value greater than long.max

This revolves around a dmd test which fails on ARM:

https://github.com/D-Programming-Language/dmd/blob/master/test/runnable/constfold.d#L321

int bug7(int x) {  return x; }
static assert(!is(typeof(bug7(cast(long)3.256679e30))));

Is it a valid test?  Or specifically, is a cast from double to long
defined if double > long.max?

The test appears to assume that cast(long)3.256679e30 will be lower
64-bits of truncated double value.  Internally, the D compiler (C++
version) used a C cast, which is undefined according to C++ spec sec
4.9.  It might work this way, might not.  Turns out ARM EABI where I
have been working in LDC lately, this cast results in -1.  Satisfies
bug7(int) and assert fails.

Does D language say anything about such casts?  If follows C++, then
test is invalid.
-- 
Dan
Apr 12 2016