Project: Standard Deviation
Write a filter program that accepts text representations of floating point values on the standard input, one per line. The program should then compute the standard deviation of a list of floating point values. Finally the program should simply output the value of the standard deviation to 16 decimal places on a single line so that it can easily be used by other programs.
Output
$ rustc StandardDeviation.rs
error: unknown format trait `g`
--> StandardDeviation.rs:24:33
|
24 | println!("{}", format!("{0:.16g}", sqrt(deviation / (count) as f64)));
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
error[E0425]: cannot find value `Utils` in this scope
--> StandardDeviation.rs:13:19
|
13 | let mut d:f64 = Utils.stodWithDefault(line, 0.0f64);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> StandardDeviation.rs:9:22
|
9 | let mut total:f64 = 0;
| --- ^
| | |
| | expected `f64`, found integer
| | help: use a float literal: `0.0`
| expected due to this
error[E0425]: cannot find function `getline` in this scope
--> StandardDeviation.rs:12:8
|
12 | while getline(line) {
| ^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> StandardDeviation.rs:17:20
|
17 | let count:isize = samples.len();
| ----- ^^^^^^^^^^^^^ expected `isize`, found `usize`
| |
| expected due to this
|
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
|
17 | let count:isize = samples.len().try_into().unwrap();
| ++++++++++++++++++++
error[E0425]: cannot find function `pow` in this scope
--> StandardDeviation.rs:22:17
|
22 | deviation += pow(sample - average,2.0f64);
| ^^^ not found in this scope
error[E0425]: cannot find function `sqrt` in this scope
--> StandardDeviation.rs:24:38
|
24 | println!("{}", format!("{0:.16g}", sqrt(deviation / (count) as f64)));
| ^^^^ not found in this scope
|
help: use the `.` operator to call the method `sqrt` on `f64`
|
24 | println!("{}", format!("{0:.16g}", (deviation / (count) as f64).sqrt()));
| ~ ~~~~~~~~
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
$ rustc StandardDeviation.rs
error: unknown format trait `g`
--> StandardDeviation.rs:24:33
|
24 | println!("{}", format!("{0:.16g}", sqrt(deviation / (count) as f64)));
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
error[E0425]: cannot find value `Utils` in this scope
--> StandardDeviation.rs:13:19
|
13 | let mut d:f64 = Utils.stodWithDefault(line, 0.0f64);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> StandardDeviation.rs:9:22
|
9 | let mut total:f64 = 0;
| --- ^
| | |
| | expected `f64`, found integer
| | help: use a float literal: `0.0`
| expected due to this
error[E0425]: cannot find function `getline` in this scope
--> StandardDeviation.rs:12:8
|
12 | while getline(line) {
| ^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> StandardDeviation.rs:17:20
|
17 | let count:isize = samples.len();
| ----- ^^^^^^^^^^^^^ expected `isize`, found `usize`
| |
| expected due to this
|
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
|
17 | let count:isize = samples.len().try_into().unwrap();
| ++++++++++++++++++++
error[E0425]: cannot find function `pow` in this scope
--> StandardDeviation.rs:22:17
|
22 | deviation += pow(sample - average,2.0f64);
| ^^^ not found in this scope
error[E0425]: cannot find function `sqrt` in this scope
--> StandardDeviation.rs:24:38
|
24 | println!("{}", format!("{0:.16g}", sqrt(deviation / (count) as f64)));
| ^^^^ not found in this scope
|
help: use the `.` operator to call the method `sqrt` on `f64`
|
24 | println!("{}", format!("{0:.16g}", (deviation / (count) as f64).sqrt()));
| ~ ~~~~~~~~
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
$ rustc StandardDeviation.rs
error: unknown format trait `g`
--> StandardDeviation.rs:24:33
|
24 | println!("{}", format!("{0:.16g}", sqrt(deviation / (count) as f64)));
| ^
|
= note: the only appropriate formatting traits are:
- ``, which uses the `Display` trait
- `?`, which uses the `Debug` trait
- `e`, which uses the `LowerExp` trait
- `E`, which uses the `UpperExp` trait
- `o`, which uses the `Octal` trait
- `p`, which uses the `Pointer` trait
- `b`, which uses the `Binary` trait
- `x`, which uses the `LowerHex` trait
- `X`, which uses the `UpperHex` trait
error[E0425]: cannot find value `Utils` in this scope
--> StandardDeviation.rs:13:19
|
13 | let mut d:f64 = Utils.stodWithDefault(line, 0.0f64);
| ^^^^^ not found in this scope
error[E0308]: mismatched types
--> StandardDeviation.rs:9:22
|
9 | let mut total:f64 = 0;
| --- ^
| | |
| | expected `f64`, found integer
| | help: use a float literal: `0.0`
| expected due to this
error[E0425]: cannot find function `getline` in this scope
--> StandardDeviation.rs:12:8
|
12 | while getline(line) {
| ^^^^^^^ not found in this scope
error[E0308]: mismatched types
--> StandardDeviation.rs:17:20
|
17 | let count:isize = samples.len();
| ----- ^^^^^^^^^^^^^ expected `isize`, found `usize`
| |
| expected due to this
|
help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit
|
17 | let count:isize = samples.len().try_into().unwrap();
| ++++++++++++++++++++
error[E0425]: cannot find function `pow` in this scope
--> StandardDeviation.rs:22:17
|
22 | deviation += pow(sample - average,2.0f64);
| ^^^ not found in this scope
error[E0425]: cannot find function `sqrt` in this scope
--> StandardDeviation.rs:24:38
|
24 | println!("{}", format!("{0:.16g}", sqrt(deviation / (count) as f64)));
| ^^^^ not found in this scope
|
help: use the `.` operator to call the method `sqrt` on `f64`
|
24 | println!("{}", format!("{0:.16g}", (deviation / (count) as f64).sqrt()));
| ~ ~~~~~~~~
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.