[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Some thoughts on integer exponentiation (and an implementation)**
**From**: Sean Conner <sean@...>
**Date**: Sun, 14 May 2017 19:13:53 -0400

It was thus said that the Great Stefan Ginsberg once stated:
>
> > On 14 May 2017, at 23:46, Sean Conner <sean@conman.org> wrote:
> >
> > 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 ...
> >
> To be clear that idea is only for the affected mathematical operators, not
> bitwise shifts.
>
> I don't consider shifting out bits the same thing as overflow, it is
> another type of operation.
Shifting is just multiplication or division by two. At the CPU level,
there is a distinction made between shifts (left (multiplication) which
shifts in 0s and right (division) which shifts in the sign bit) and rotates
(shifts the bits, rotating in the carry bit).
-spc