called f by value
This commit is contained in:
@@ -6,11 +6,11 @@ use crate::point::Point;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Function{
|
||||
f: fn(&f64)->f64,
|
||||
f: fn(f64)->f64,
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub fn new(f: fn(&f64) -> f64) -> Function {
|
||||
pub fn new(f: fn(f64) -> f64) -> Function {
|
||||
return Function {f};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ impl Function {
|
||||
}
|
||||
|
||||
fn includes(&self, point: &Point) -> bool {
|
||||
let y_0: f64 = (self.f)(&point.get_x());
|
||||
let y_0: f64 = (self.f)(point.get_x());
|
||||
return y_0.abs() > point.get_y().abs() && y_0 * point.get_y() >= 0_f64;
|
||||
}
|
||||
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -14,21 +14,22 @@ mod bounds;
|
||||
mod function;
|
||||
mod plot;
|
||||
|
||||
const THREAD_CNT: usize = 8;
|
||||
const THREAD_CNT: usize = 20;
|
||||
const SAMPLE_LIMIT: usize = 100_000_000;
|
||||
const SUB_SAMPLES: [usize; 3] = [1, 2, 5];
|
||||
const SAMPLES_PER_ITERATION: usize = 250;
|
||||
|
||||
fn f(x: &f64) -> f64 {
|
||||
E.powf(*x) * (1.0 / (*x).sin()).cos() + (*x).powf(2.0)
|
||||
fn f(x: f64) -> f64 {
|
||||
E.powf(x) * (1.0 / x.sin()).cos() + x.powf(2.0)
|
||||
//E.powf(-x) * x.tan() * (2.0 / (2.0 * x).sin()).cos() + 1.0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let bounds: Bounds = Bounds::new(LinearBounds::new(3.1_f64, 3.2_f64), LinearBounds::new(-15_f64, 35_f64));
|
||||
let bounds: Bounds = Bounds::new(LinearBounds::new(-1_f64, 1_f64), LinearBounds::new(0_f64, 10_f64));
|
||||
let func: Function = Function::new(f);
|
||||
|
||||
let start: Instant = Instant::now();
|
||||
println!("{}\n{}ms", func.approximate(&bounds, 10_000_000, THREAD_CNT), start.elapsed().as_millis())
|
||||
println!("{}\n{}ms", func.approximate(&bounds, 1_000_000_000, THREAD_CNT), start.elapsed().as_millis())
|
||||
|
||||
//simulate(&bounds, &func)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user