Bringing up the issue of numerical constraints again

liorean liorean at gmail.com
Mon Nov 12 16:56:39 PST 2007


Hello!

Since we now have a namespace for uint specific math operations, and
discussion in another thread about using pragmas for throwing if
assigning to ReadOnly properties... Is it possible we could have a
look at the idea of adding constrained primitive types or adding a
pragma changing the mechanism for, or adding a separate set of
operations, constraining number types by the simple rule of (input >
output_type.MAX_VALUE) and (input < output_type.MIN_VALUE) throwing an
out-of-bounds error.

I'm a little concerned that a type of uint allows assigning negatives
with a silent round-the-corner conversion and allows values of NaN and
Infinity. (I imagine for example the DOM interfaces that have uint
constraints really would like these to throw an out-of-bounds
exception or similar.)

Also, the RI gives an Overflow exception for values 2^32 or greater,
which I'm not sure whether it's the intended behaviour or a result of
the underlying implementation that is in fact intended to fail
silently like the other cases.

>> function fn(input:uint):uint input;
>> fn(0x7fffffff);
2147483647
>> fn(-0x80000000);
2147483648
>> fn(Infinity);
0
>> fn(NaN);
0
>> fn(0x100000000);
unhandled exception: Overflow

>> function fn(input:int):int input;
>> fn(0x7fffffff)
2147483647
>> fn(0x80000000)
-2147483648
>> fn(-0x80000000)
-2147483648
>> fn(NaN)
0
>> fn(Infinity)
0
>> fn(0x100000000)
unhandled exception: Overflow
-- 
David "liorean" Andersson



More information about the Es4-discuss mailing list