Averages/Mean time of day: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: minor tidy, use builtin atan2, name h/m/s)
Line 1,539: Line 1,539:


=={{header|Phix}}==
=={{header|Phix}}==
<lang Phix>function atan2(atom y, atom x)
<lang Phix>function MeanAngle(sequence angles)
atom x = 0, y = 0
return 2*arctan((sqrt(power(x,2)+power(y,2))-x)/y)
for i=1 to length(angles) do
end function
atom ai_rad = angles[i]*PI/180
function MeanAngle(sequence angles)
atom x=0, y=0, ai_rad
integer l=length(angles)
for i=1 to l do
ai_rad = angles[i]*PI/180
x += cos(ai_rad)
x += cos(ai_rad)
y += sin(ai_rad)
y += sin(ai_rad)
Line 1,569: Line 1,563:
if s<0 then s+=360 end if
if s<0 then s+=360 end if
s = 24*60*60*s/360
s = 24*60*60*s/360
s = sprintf("%02d:%02d:%02d",{floor(s/3600),floor(remainder(s,3600)/60),remainder(s,60)})
atom hours = floor(s/3600),
mins = floor(remainder(s,3600)/60),
secs = remainder(s,60)
s = sprintf("%02d:%02d:%02d",{hours,mins,secs})
end if
end if
return s
return s
end function
end function


printf(1,"Mean Time is %s\n",{toHMS(MeanAngle(Times))})
printf(1,"Mean Time is %s\n",{toHMS(MeanAngle(Times))})</lang>
{} = wait_key()</lang>
{{out}}
{{out}}
<pre>
<pre>