Logo

Programming-Idioms

History of Idiom 202 > diff from v11 to v12

Edit summary for version 12 by CeaselessBanana:
New Rust implementation by user [CeaselessBanana]

Version 11

2020-01-06, 11:42:22

Version 12

2020-03-17, 13:20:52

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

Code
let s = data.iter().map(|x| x.powi(2)).sum::<f32>();
Doc URL
https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.powi