lua-users home
lua-l archive

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


On Apr 4, 2019, at 5:25 PM, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

> local function cin(x) 
>    local r, p, s, n, R = x, x, x*x, 0 
>    repeat 
>       R, n, p = r, n+1, p*s 
>       r = r + maclaurin_of_cin(n) * p 
>    until r == R 
>    return r 
> end 

How does your maclaurin_of_cin work ? 
It looks like magic to me :-)

To handle big cin argument, I use identity cin(x) = asin(cin(sin(x)))
So, adding this line to your cin(x) is all that is needed.

if math.abs(x) >= 0.7 then return math.asin(cin(math.sin(x))) end

With this 1 line patch:

x = 2.019
cin(x) = 1.02692 331869 35764
cin(cin(x)) = 0.95662 892999 61186
cin(cin(cin(x))) = 0.90122 698939 98124  
math.sin(x)      = 0.90122 698939 98126

Amazing accuracy !