This is my code to calculate sunrise set . There seems no error . But while calling the sub "nan" is returned . can any one help me to find the problem ?
B4X:
Sub SunRiseSet(JulianDay As Double,Latitude As Double,Longitude As Double,timeZone As Double) As Double()
Dim st(3) As Double
Dim t,l,g,ec,lambda,a,b,c,d,e As Double
t = JulianDay - 0.5 - 2451545
t = t/36525
l = Round360(280.460 + 36000.770 * t)
g = Round360(357.528 + 35999.050 * t) ' (Mean anomaly)
ec = 1.915 * SinD(g) + 0.020 * SinD(2*g) '(eq centre correction)
lambda = Round360(l + ec) '(ecliptic longitude of Sun)
a = lambda + 180
b = SinD(a) * SinD(23.45)
c = ASinD(b)
d = TanD(c) * TanD(Latitude)
d = ASinD(d)
e = (1 - CosD(23.45)) * SinD(a) * CosD(a) / CosD(c)
e = ASinD(e):Log(e)
a = timeZone * 15 - Longitude
st(0) = (89.1666667 + d - e + a + ec) / 15'
st(1) = (270.8333 - d - e + a + ec) / 15
st(2) = 30.2778 - d / 3
Return st
End Sub