Last active
August 29, 2015 14:02
-
-
Save espadrine/2046d0baf7d70a9544b5 to your computer and use it in GitHub Desktop.
Fix from [benh].
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::f64::consts::PI; | |
fn deriv(f: |f64| -> f64, g: |(|f64| -> f64)|) { | |
g(|x: f64| -> f64 { | |
let epsilon = 0.0000000001; | |
(f(x + epsilon) - f(x)) / epsilon | |
}); | |
} | |
fn main() { | |
println!("cos(pi) = {}", PI.cos()); | |
deriv(|x|x.sin(), |myCos| { | |
println!("cos(pi) = {}", myCos(PI)) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment