Email List: Xaustin-review-lX
[All Lists]

Re: Defect in XSH exp (revised II)

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Re: Defect in XSH exp (revised II)
From: Loic Domaigne <yyyyyyyy@xxxxxxx>
Date: Thu, 17 Jul 2003 20:34:34 +0200 (MEST)
References: <Pine.BSO.4.21.0307171239180.14996-100000@xxxxxx>
Dr Dragan Cvetkovic wrote:

> I think you will need to #include <math.h>.

Of course... I forgot to copy-paste this line... 

Hope that's OK now.
Loic.

------------------------------------------------------------------------

Computing the density of the standard normal distribution

This function shows a straightforward implementation for
the density of the standard normal distribution using exp()

#include <math.h>

double
normal_density (double  x
                )
{ 
  return exp(-x*x/2) / sqrt (2*M_PI);
}

Note: For real life problems, where normal_density() is called many, 
many times (let's say 10 millions or more), this implementation
is not particularly efficient.  Possible improvements include:

- compute the constant term sqrt(2*M_PI) only once.
- transform the division to a multiplication. 

If you are planning to do serious numerical works, get a good 
book on numerical computations or advices from an expert.
[ I guess this last advice applies to all XSH math functions ]

-- 
+++ GMX - Mail, Messaging & more  http://www.gmx.net +++

Jetzt ein- oder umsteigen und USB-Speicheruhr als Prämie sichern!

<Prev in Thread] Current Thread [Next in Thread>