[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sc-devel] When integers go bad



I also think this is not optimal. I've had hard to find bugs with integer arithmetics because of this.

Hm, OK, well maybe I'm just spoilt by environments like Octave or
Matlab that give you inf when you go off the scale, which is a really
useful warning that you've hit the buffers! (Maybe they use floats
implicitly even for integers.)

Thanks
Dan


2008/2/26, James Harkins <jamshark70@xxxxxxxxx>:
 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@xxxxxxxxx> 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@xxxxxxxxxxxxxxxxx
  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@xxxxxxxxxxxxxxx
  http://lists.create.ucsb.edu/mailman/listinfo/sc-devel



--
http://www.mcld.co.uk
_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://lists.create.ucsb.edu/mailman/listinfo/sc-devel


--





.