diff --git a/src/distribution/mod.rs b/src/distribution/mod.rs index 23ae7ec5..a9718ee6 100644 --- a/src/distribution/mod.rs +++ b/src/distribution/mod.rs @@ -101,7 +101,9 @@ pub trait ContinuousCDF: Min + Max { /// let n = Uniform::new(0.0, 1.0).unwrap(); /// assert_eq!(0.5, n.sf(0.5)); /// ``` - fn sf(&self, x: K) -> T; + fn sf(&self, x: K) -> T { + T::one() - self.cdf(x) + } /// Due to issues with rounding and floating-point accuracy the default /// implementation may be ill-behaved. @@ -167,7 +169,9 @@ pub trait DiscreteCDF: Min + Max { /// let n = DiscreteUniform::new(1, 10).unwrap(); /// assert_eq!(0.4, n.sf(6)); /// ``` - fn sf(&self, x: K) -> T; + fn sf(&self, x: K) -> T { + T::one() - self.cdf(x) + } /// Due to issues with rounding and floating-point accuracy the default implementation may be ill-behaved /// Specialized inverse cdfs should be used whenever possible.