Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/main.rs
This commit is contained in:
2024-06-03 09:55:48 +02:00
2 changed files with 9 additions and 7 deletions

View File

@@ -6,11 +6,11 @@ use crate::point::Point;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub struct Function{ pub struct Function{
f: fn(&f64)->f64, f: fn(f64)->f64,
} }
impl Function { impl Function {
pub fn new(f: fn(&f64) -> f64) -> Function { pub fn new(f: fn(f64) -> f64) -> Function {
return Function {f}; return Function {f};
} }
@@ -19,7 +19,7 @@ impl Function {
} }
fn includes(&self, point: &Point) -> bool { 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; return y_0.abs() > point.get_y().abs() && y_0 * point.get_y() >= 0_f64;
} }

View File

@@ -14,17 +14,17 @@ mod bounds;
mod function; mod function;
mod plot; mod plot;
const THREAD_CNT: usize = 8; const THREAD_CNT: usize = 20;
const SAMPLE_LIMIT: usize = 100_000_000; const SAMPLE_LIMIT: usize = 100_000_000;
const SUB_SAMPLES: [usize; 3] = [1, 2, 5]; const SUB_SAMPLES: [usize; 3] = [1, 2, 5];
const SAMPLES_PER_ITERATION: usize = 250; const SAMPLES_PER_ITERATION: usize = 250;
fn f(x: &f64) -> f64 { fn f(x: f64) -> f64 {
E.powf(*x) * (1.0 / (*x).sin()).cos() + (*x).powf(2.0) E.powf(x) * (1.0 / x.sin()).cos() + x.powf(2.0)
} }
fn main() { 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(3.1_f64, 3.2_f64), LinearBounds::new(-10_f64, 35_f64));
let func: Function = Function::new(f); let func: Function = Function::new(f);
//let start: Instant = Instant::now(); //let start: Instant = Instant::now();
@@ -48,6 +48,8 @@ fn simulate(bounds: &Bounds, func: &Function) {
println!(); println!();
} }
sample_cnt *= 10; sample_cnt *= 10;
}
result.print();
let file: io::Result<File> = File::create(format!("output{}.json", sample_cnt.ilog10())); let file: io::Result<File> = File::create(format!("output{}.json", sample_cnt.ilog10()));
if file.is_err() { if file.is_err() {