Well, first, this is NOT for a class, test, or other type of student type.
I am a screenwriter for a game, and I am trying to implement a math library for everyone, and unfortunately, all I have for me is a very simple lua. The embedded version cannot be modified and does not contain libraries. For those who are wondering for scripting at Fold.It.
Here is what I have ...
math={}
math.fact = function(b) if(b==1)or(b==0) then return 1 end e=1 for c=b,1,-1 do e=e*c end return e end
math.pow = function(b,p) e=b if(p==0) then return 1 end if(p<0) then p=p*(-1) end for c=p,2,-1 do e=e*b end return e end
math.cos = function(b,p) e=0 p=p or 10 for i=1,p do e=e+(math.pow(-1,i)*math.pow(b,2*i)/math.fact(2*i)) end return e end
To clarify above, math.fact returns a factorial, which is returned with an accuracy of 10 points of accuracy and is a new function that I made to calculate the cosine.
Math.pow is also a new feature for handling returning credentials, also working as expected.
The problem is with the cosine function. Its returning unexpected meanings. It’s easier to digest the version (I wrote my material in the hyperfine library) ...
function math.cos(value,precision)
result=0
precision=precision or 10
for i=1,precision do
result=result+(math.pow(-1,i)*math.pow(value,2*i)/math.fact(2*i))
end
return e
end
The problem is that with these print functions (math.cos (90)) it returns 4.77135 ... when I expect -0.44807 ... (based on calc in scientific mode or using the online tool to cos (90) )
I also have problems with sin and tanning, but they are similarly written in cos, which seems to have been done in many languages. If I can understand what I'm doing wrong, I can fix them all.
EDIT: fixed typo