(data: &[f64])
| 91 | } |
| 92 | |
| 93 | fn standard_deviation(data: &[f64]) -> f64 { |
| 94 | let mut mean = 0.0; |
| 95 | let mut sum_squares = 0.0; |
| 96 | let mut count = 0.0; // Use f64 directly for count to avoid casting |
| 97 | |
| 98 | for &x in data { |
| 99 | count += 1.0; |
| 100 | let delta = x - mean; |
| 101 | mean += delta / count; |
| 102 | sum_squares += delta * (x - mean); |
| 103 | } |
| 104 | |
| 105 | // Return 0.0 if data is empty or has only one element |
| 106 | if count < 2.0 { |
| 107 | return 0.0; |
| 108 | } |
| 109 | |
| 110 | // Calculate and return sample standard deviation |
| 111 | (sum_squares / (count - 1.0)).sqrt() |
| 112 | } |
| 113 | |
| 114 | |
| 115 | fn main() { |
nothing calls this directly
no outgoing calls
no test coverage detected