flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 203: Calculate mean and standard deviation
Idiom # 203: Calculate mean and standard deviation
See
programming-idioms.org
:
Code
mean(a Sequence f64) => (sum a) / a.count.as_f64 stddev²(a Sequence f64) => m := mean a mean (a.map_sequence f64 x->(x - m)**2) # NYI: no sqrt yet: # # stddev := stddev².sqrt
What are effects?
Running Example
ex203 is a := [0.0, 8.0, 15.0, 47.0, 11.0] mean(a Sequence f64) => (sum a) / a.count.as_f64 stddev²(a Sequence f64) => m := mean a mean (a.map_sequence f64 x->(x - m)**2) # NYI: no sqrt yet: # # stddev := stddev².sqrt say "mean of $a is {mean a}" say "stddev² of $a is {stddev² a}"
What are effects?
next: Idiom # 204: Return fraction and exponent of a real number