Skip to content

Instantly share code, notes, and snippets.

@espadrine
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espadrine/2046d0baf7d70a9544b5 to your computer and use it in GitHub Desktop.
Save espadrine/2046d0baf7d70a9544b5 to your computer and use it in GitHub Desktop.
Fix from [benh].
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