Oh Dear
bearophile
bearophileHUGS at lycos.com
Sun Jul 12 14:24:38 PDT 2009
Michiel Helvensteijn:
> Walter, surely this test shouldn't take more than a minute for you (or
> anyone else with a D compiler installed). Just see what DMD outputs for:
>
> 8 / 3
> 8 / (-3)
> (-8) / 3
> (-8) / (-3)
> 8 % 3
> 8 % (-3)
> (-8) % 3
> (-8) % (-3)
You don't know codepad.org :-)
D version:
http://codepad.org/Mbi9HBjz
void main() {
writefln( 8 / 3);
writefln( 8 / (-3));
writefln( (-8) / 3);
writefln( (-8) / (-3));
writefln( 8 % 3);
writefln( 8 % (-3));
writefln( (-8) % 3);
writefln( (-8) % (-3));
}
D output:
2
-2
-2
2
2
2
-2
-2
-------------
Python version:
http://codepad.org/Mbi9HBjz
print 8 // 3
print 8 // (-3)
print (-8) // 3
print (-8) // (-3)
print 8 % 3
print 8 % (-3)
print (-8) % 3
print (-8) % (-3)
Python output:
2
-3
-3
2
2
-1
1
-2
---------------------
BCS:
>Short of overflow detection (and the overhead that causes) I think this is an issue inherent to discreet systems (a.k.a. all computer systems) that we just have to live with.<
I don't understand what's the purpose of overflow detection in this context. Are those differences between the D and Python output caused by overflows?
Bye and thank you,
bearophile
More information about the Digitalmars-d
mailing list