From 928e4b2541ce3dabc9f5e6d799542bb96a02284d Mon Sep 17 00:00:00 2001 From: Joseph Caudle Date: Sat, 10 Oct 2015 00:01:57 -0400 Subject: [PATCH] Run rustfmt on librand/distributions/normal.rs --- src/librand/distributions/normal.rs | 38 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/librand/distributions/normal.rs b/src/librand/distributions/normal.rs index cc70a695c8d..7fe8b6e8806 100644 --- a/src/librand/distributions/normal.rs +++ b/src/librand/distributions/normal.rs @@ -32,13 +32,13 @@ pub struct StandardNormal(pub f64); impl Rand for StandardNormal { - fn rand(rng: &mut R) -> StandardNormal { + fn rand(rng: &mut R) -> StandardNormal { #[inline] fn pdf(x: f64) -> f64 { - (-x*x/2.0).exp() + (-x * x / 2.0).exp() } #[inline] - fn zero_case(rng: &mut R, u: f64) -> f64 { + fn zero_case(rng: &mut R, u: f64) -> f64 { // compute a random number in the tail by hand // strange initial conditions, because the loop is not @@ -56,15 +56,19 @@ fn zero_case(rng: &mut R, u: f64) -> f64 { y = y_.ln(); } - if u < 0.0 { x - ziggurat_tables::ZIG_NORM_R } else { ziggurat_tables::ZIG_NORM_R - x } + if u < 0.0 { + x - ziggurat_tables::ZIG_NORM_R + } else { + ziggurat_tables::ZIG_NORM_R - x + } } - StandardNormal(ziggurat( - rng, - true, // this is symmetric - &ziggurat_tables::ZIG_NORM_X, - &ziggurat_tables::ZIG_NORM_F, - pdf, zero_case)) + StandardNormal(ziggurat(rng, + true, // this is symmetric + &ziggurat_tables::ZIG_NORM_X, + &ziggurat_tables::ZIG_NORM_F, + pdf, + zero_case)) } } @@ -89,12 +93,14 @@ pub fn new(mean: f64, std_dev: f64) -> Normal { assert!(std_dev >= 0.0, "Normal::new called with `std_dev` < 0"); Normal { mean: mean, - std_dev: std_dev + std_dev: std_dev, } } } impl Sample for Normal { - fn sample(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) } + fn sample(&mut self, rng: &mut R) -> f64 { + self.ind_sample(rng) + } } impl IndependentSample for Normal { fn ind_sample(&self, rng: &mut R) -> f64 { @@ -110,7 +116,7 @@ fn ind_sample(&self, rng: &mut R) -> f64 { /// std_dev**2)` distributed. #[derive(Copy, Clone)] pub struct LogNormal { - norm: Normal + norm: Normal, } impl LogNormal { @@ -126,7 +132,9 @@ pub fn new(mean: f64, std_dev: f64) -> LogNormal { } } impl Sample for LogNormal { - fn sample(&mut self, rng: &mut R) -> f64 { self.ind_sample(rng) } + fn sample(&mut self, rng: &mut R) -> f64 { + self.ind_sample(rng) + } } impl IndependentSample for LogNormal { fn ind_sample(&self, rng: &mut R) -> f64 { @@ -179,7 +187,7 @@ mod bench { use std::prelude::v1::*; use self::test::Bencher; use std::mem::size_of; - use distributions::{Sample}; + use distributions::Sample; use super::Normal; #[bench] -- 2.44.0