Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Math overflow

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: > >>> 2133147400 + 26604769 > > ** Math Error: Math or number overflow > ** Near: 2133147400 + 26604769 > >>> 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-