lua-users home
lua-l archive

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


> -----Oorspronkelijk bericht-----
> Van: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
> Namens Christopher Kappe
> Verzonden: Thursday, 14 April, 2016 12:30
> Aan: lua-l@lists.lua.org
> Onderwerp: compute cubic root with negative argument
> 
> Hello,
> 
> I just noticed that it is not possible to compute the cubic root of a
> negative number. See e.g.
> print( math.pow( -27, 1/3 ) ) --> -nan instead of -3 The same is true for
> the ^ operator (not surprising).
> 
> This probably stems from the fact that the result of the n-th root of a
> negative number is not real if n is even (e.g. sqrt(-1) = (-1)^(1/2) = i).
> However, (-3)^3 = -27 and likewise should hold that (-27)^(1/3) = -3.
> This works by the way with Google (try googling f(x) = x^(1/3) and you
> will see the graph of the function also for the negative x-axis).

I didn't know Google could do that. Very nice!