Jump to content

Averages/Mean time of day: Difference between revisions

m
→‎{{header|Nim}}: Update code to work with newer versions, remove reimplementations of stdlib functions
(Add Rust implementation)
m (→‎{{header|Nim}}: Update code to work with newer versions, remove reimplementations of stdlib functions)
Line 1,365:
 
=={{header|Nim}}==
{{works with|Nim|0.20.0+}}
<lang nim>import math, complex, strutils, sequtils
proc rect(r, phi: float): Complex = (r * cos(phi), sin(phi))
proc phase(c: Complex): float = arctan2(c.im, c.re)
proc radians(x: float): float = (x * Pi) / 180.0
proc degrees(x: float): float = (x * 180.0) / Pi
proc meanAngle(deg: openArray[float]): float =
var c: Complex[float]
for d in deg:
c += rect(1.0, radiansdegToRad(d))
degreesradToDeg(phase(c / float(deg.len)))
proc meanTime(times: openArray[string]): string =
Cookies help us deliver our services. By using our services, you agree to our use of cookies.