# [erlang-questions] How to write this code better?

David Mercer <>
Fri Apr 11 23:32:14 CEST 2008

```I'd write it something like:

. . .
% Check it
Declination2 = if
Declination1 > 89.99  -> 89.99;
Declination1 < -89.99 -> -89.99;
true                  -> Declination1
end.

Cheers,

DBM

-----Original Message-----
From:
[mailto:] On Behalf Of Jilani Khaldi
Sent: Friday, April 11, 2008 16:00
To: Erlang Questions List
Subject: [erlang-questions] How to write this code better?

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
_______________________________________________
erlang-questions mailing list

http://www.erlang.org/mailman/listinfo/erlang-questions

```