fuzion-lang.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 x->(x - m)**2) stddev(a Sequence f64) => f64.type.sqrt (stddev² a)
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 x->(x - m)**2) stddev(a Sequence f64) => f64.type.sqrt (stddev² a) say "mean of $a is {mean a}" say "stddev² of $a is {stddev² a}" say "stddev of $a is {stddev a}"
What are effects?
next: Idiom # 204: Return fraction and exponent of a real number