lua-users home
lua-l archive

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


It was thus said that the Great Stefan Ginsberg once stated:
> 
> Something I would find more useful is if overflowed integer results were
> returned as nil (i.e. 123^456 == nil).
> Not just for '^' but for all relevant integer operations. This would also
> make unsigned numbers more manageable.

  Such checks add overhead to Lua (but as usual, one would have to test to
see of the overhead is unacceptable).  Unfortunately, there is no cheap way
to check for overflow in C (unlike assembly [1]).

  Second, I'm not sure if I like returning nil.  

	a = 1
	b = 63
	c = 1

	x = (1 << b) + c

	stdin:1: attempt to perform arithmetic on a nil value
	stack traceback:
	        stdin:1: in main chunk
	        [C]: in ?
> 
  Okay, that doesn't happen now---what happens now is that x =
9223372036854775807 instead of -9223372036854775809 because of rollover. 
I can see an argument for it, but ...

  -spc (but I'm not sure if I want to see how sloppy I've been with math ... )

[1]	http://boston.conman.org/2015/09/07.1

	It's not much overhead in time, but it does increase the memory
	usage of the code because of the overhead of checking for overflow.