lua-users home
lua-l archive

Re: Unexpected calculation result with Lua53

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


On May 4, 2015, at 11:56 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> I must confess I learned something new from this discution. From now
> one, whenever I teach the factorial function in C, I will write it like
> this:
> 
> double fact (double n) {
> double a = 1;
> while (n > 0) a *= n--;
> return a;
> }
> 
> After all, it gives "better" results then the old-fashioned version :-)
Down vs up is fun.
> n=1 for i = 1,80 do n = n * i end print(n) n1=n
7.1569457046264e+118
> n=1 for i = 80,1,-1 do n = n * i end print(n) n2=n
7.1569457046264e+118
> return n2-n1
1.7917957937422e+103
Only a few googols of difference....

AltStyle によって変換されたページ (->オリジナル) /