Re: sine and cosine functions
Re: sine and cosine functions
- Subject: Re: sine and cosine functions
- From: Deivy Petrescu <email@hidden>
- Date: Fri, 27 Feb 2004 15:12:53 -0500
At 11:49 AM -0700 2/27/04, Doug McNutt wrote:
At 10:44 -0600 2/27/04, ehsan saffari wrote:
Thanks Doug, Deivy & Emmanuel
This kind of AppleScripting is fun.
Agreed.
I just think that the original As is fine. If you
want to improve it I'll suggest the following
----------------------------
on cosine_of(x) -- degrees
set x to x mod 360
if x = 0 then return 1
if (x mod 90 = 0) then
if (x mod 180 = 0) then
return -1
else
return 0
end if
else
set x to x * pi / 180
set {answer, numerator,
denominator, factor} to {0, 1, 1, -(x ^ 2)}
repeat with i from 2 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
end if
return answer
end cosine_of
----------------------------
----------------------------
on sine_of(x) -- degrees
set x to x mod 360
if x = 0 or (x mod 180 = 0) then return 0
if (x mod 90 = 0) then
if (x mod 270 = 0) then
return -1
else
return 1
end if
else
set x to x * pi / 180
set {answer, numerator,
denominator, factor} to {0, x, 1, -(x ^ 2)}
repeat with i from 3 to 40 by 2
set answer to answer + numerator / denominator
set numerator to numerator * factor
set denominator to denominator * i * (i - 1)
end repeat
end if
return answer
end sine_of
----------------------------
--
Regards
Saudagues
Deivy
http://www.dicas.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.