Integer overflow and underflow semantics?

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 22 04:40:26 PDT 2014


On 07/22/14 08:15, Iain Buclaw via Digitalmars-d wrote:
> On 21 Jul 2014 22:10, "Artur Skawina via Digitalmars-d" <digitalmars-d at puremagic.com <mailto:digitalmars-d at puremagic.com>> wrote:
>> For D that is not possible -- if an expression is valid at run-time
>> then it should be valid at compile-time (and obviously yield the same
>> value).
> 
> ...most of the time.
> 
> CTFE is allowed to do things at an arbitrary precision in mid-flight when evaluating an expression.

That will work for FP, where excess precision is allowed, but will not work
for integer arithmetic. Consider code which uses hashing and hash-folding
functions which rely on wrapping arithmetic. If you increase the precision
then those functions will yield different values. Now a hash value
calculated at CT is invalid at RT...

artur


More information about the Digitalmars-d mailing list