« Return to Thread: When integers go bad

Re: When integers go bad

by James Harkins-2 :: Rate this Message:

Reply to Author | View in Thread

This is standard behavior for integer arithmetic. Keeping it simple,
if you have 8 bits only:

2r01111111 == 127
+1
----
2r10000000 == -128

Actually, n - 1 works by addition. 5 - 1 = 5 + (-1) = 5 + (2^8 - 1)

2r00000101 + 2r11111111 = 2r00000100 or 4.

I think it's more a matter of being careful, or of .asFloat'ing
everything when the range might get very large.
hjh


On Tue, Feb 26, 2008 at 4:53 PM, Dan Stowell <danstowell@...> wrote:

> Hi -
>
>  SC goes a bit strange when integers go off the scale:
>
>   1410889248 * 99;   // Results in -2055885216
>
>  Is this as designed? Since it returns an Integer, it's pretty
>  dangerous since it can continue to be used in calculations and can
>  corrupt. Would be better if it returned inf, or perhaps even threw
>  some kind of exception. Is that feasible?


--
James Harkins /// dewdrop world
jamshark70@...
http://www.dewdrop-world.net

"Come said the Muse,
Sing me a song no poet has yet chanted,
Sing me the universal."  -- Whitman
_______________________________________________
Sc-devel mailing list
Sc-devel@...
http://lists.create.ucsb.edu/mailman/listinfo/sc-devel

 « Return to Thread: When integers go bad