Subject Re: Problem with quotes
Author Adam
--- In firebird-support@yahoogroups.com, Ali Gökçen <alig@e...> wrote:
>
>
> > = Cast(((n * (n+1)) / 2) as Integer)
> >
> > ( Does that make me a real programmer ;-) )
>
> Yup, it makes you with a little optimization.
> (if you cancel the casting :P )
>
> (n*n+n)/2, no cast, no paranthesis soup. ;)
>
> Actually this was the light version of my ask.
> The original is: how can you put sum of numbers from n to m.

((m*m+1)-(n*n+1))/2

I am sure we can optimise the divide by 2 with a right shift op ;)