diff --git a/src/Numerics/Distributions/Cauchy.cs b/src/Numerics/Distributions/Cauchy.cs index c8af2860..f6d9b1bd 100644 --- a/src/Numerics/Distributions/Cauchy.cs +++ b/src/Numerics/Distributions/Cauchy.cs @@ -179,7 +179,8 @@ namespace MathNet.Numerics.Distributions /// public double Density(double x) { - return 1.0/(Constants.Pi*_scale*(1.0 + (((x - _location)/_scale)*((x - _location)/_scale)))); + var z = (x - _location)/_scale; + return 1.0/(Constants.Pi*_scale*(1.0 + z * z)); } /// @@ -190,7 +191,8 @@ namespace MathNet.Numerics.Distributions /// public double DensityLn(double x) { - return -Math.Log(Constants.Pi*_scale*(1.0 + (((x - _location)/_scale)*((x - _location)/_scale)))); + var z = (x - _location)/_scale; + return -Math.Log(Constants.Pi*_scale*(1.0 + z * z)); } /// @@ -283,9 +285,9 @@ namespace MathNet.Numerics.Distributions throw new ArgumentException("Invalid parametrization for the distribution."); } - return 1.0/(Constants.Pi*scale*(1.0 + (((x - location)/scale)*((x - location)/scale)))); + var z = (x - location)/scale; + return 1.0/(Constants.Pi*scale*(1.0 + z * z)); } - /// /// Computes the log probability density of the distribution (lnPDF) at x, i.e. ln(∂P(X ≤ x)/∂x). /// @@ -301,7 +303,8 @@ namespace MathNet.Numerics.Distributions throw new ArgumentException("Invalid parametrization for the distribution."); } - return -Math.Log(Constants.Pi*scale*(1.0 + (((x - location)/scale)*((x - location)/scale)))); + var z = (x - location)/scale; + return -Math.Log(Constants.Pi*scale*(1.0 + z * z )); } ///