[erlang-questions] How to write this code better?
Jilani Khaldi
jilani@REDACTED
Fri Apr 11 23:00:21 CEST 2008
Hi All,
I am translating this Pascal code:
t := 2*3.14159*((JD - 1) / 365.0);
declination := (0.322003 - 22.971 * cos(t)
- 0.357898 * cos(2*t)
- 0.14398 * cos(3*t)
+ 3.94638 * sin(t)
+ 0.019334 * sin(2*t)
+ 0.05928 * sin(3*t));
// Check it
if (declination > 89.99) then declination := 89.99;
if (declination < -89.99) then declination := -89.99;
to Erlang:
T1 = 2*3.14159*((JD - 1) / 365.0),
Declination1 = (0.322003-22.971*cos(T1)
-0.357898*cos(2*T1)
-0.14398*cos(3*T1)
+3.94638*sin(T1)
+0.019334*sin(2*T1)
+0.05928*sin(3*T1)),
% Check it
if (Declination1 > 89.99) ->
Declination2 = 89.99;
true ->
Declination2 = Declination1
end,
if (Declination1 < -89.99) ->
Declination2 = -89.99;
true ->
Declination2 = Declination1
end,
Declination2.
The Erlang code works but I think there is at least one way to write it
better.
Thank you!
--
***
Jilani KHALDI
http://www.dotpas.org
More information about the erlang-questions
mailing list