Math overflow
[1/5] from: atruter:labyrinth:au at: 6-Jul-2003 18:19
I vaguely remember this coming up before, but can anyone explain why the
first expression fails and the second succeeds:
>> 2133147400 + 26604769
** Math Error: Math or number overflow
** Near: 2133147400 + 26604769
>> 9999999999 + 99999999
== 10099999998
Regards,
Ashley
[2/5] from: roland::hadinger::arcor::de at: 6-Jul-2003 13:57
You're using different types:
>> type? 2133147400 ; < 2 ** 31
== integer!
>> type? 9999999999 ; >= 2 ** 31
== decimal!
>> type? 9999999999 + 99999999
== decimal!
Adding integer values produces an integer overflow if the
result can't be represented as a 32 bit signed integer.
Adding decimal values does not overflow unless the result
exceeds +/-1.79769313486231e308.
Adding a decimal and an integer value promotes the integer
to a decimal first, then the decimal result is calculated.
[3/5] from: joel:neely:fedex at: 6-Jul-2003 7:15
Hi, Ashley,
It's all in the types.
Ashley Truter wrote:
> I vaguely remember this coming up before, but can anyone explain
> why the first expression fails and the second succeeds:
<<quoted lines omitted: 3>>
>>> 9999999999 + 99999999
> == 10099999998
Take a look at this:
>> type? 2133147400
== integer!
>> type? 26604769
== integer!
versus this:
>> type? 9999999999
== decimal!
>> type? 99999999
== integer!
The behavior of the addition operator changes based on the type
of the left-hand argument.
The first case attempts to use integer addition and overflows
the valid range for integer values. The second case uses
floating-point addition, as the left-hand value (silently) is
viewed as floating-point, and therefore does *not* overflow
the floating-point range.
-jn-
[4/5] from: antonr:iinet:au at: 7-Jul-2003 0:44
Your first example starts with a small
enough number to be an integer! so it
overflows when the integer limit is reached.
The second is bigger, so it starts out life as
a decimal! and you haven't added enough to
overflow a decimal so it's ok.
Anton.
[5/5] from: tomc:darkwing:uoregon at: 8-Jul-2003 8:35
I am sure others have explained aleready but here are some hints
>> type? 2133147400
== integer!
>> type? 9999999999
== decimal!
and
>> 99999999999999 + 999999999999
== 100999999999998
>> 99999999999999 + 999999999999.4
== 100999999999998
On Sun, 6 Jul 2003, Ashley Truter wrote:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted