delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/03/20/12:43:21

To: John Carter <ECE AT dwaf-hri DOT pwv DOT gov DOT za>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: erf, and the *rand48 functions
Date: Mon, 20 Mar 1995 10:15:30 EST
From: David Goldschmidt <gold AT ccr-p DOT ida DOT org>

>>>>> "John" == John Carter <ECE AT dwaf-hri DOT pwv DOT gov DOT za> writes:

    >> The linker complains about these functions with an "unresolved
    >> externals" message.
    >> 
    >> If they're unimplemented, can you tell me where I can get online
    >> sources for them?  (My Abramowitz & Stegun is in storage...
    John> I couldn't find them either, except as headers in the .h file, so
    John> here is something I created/took from A&S...

    John> #include <math.h> double erf( double x) { const double a1 =
    John> 0.3480242, a2=-0.0958798, a3=0.7478556, p=0.47047; double t;

    John>   if( x < 0.0) return -erf( -x); t = 1.0 / ( 1.0 + p * x); return
    John> 1.0 - t * (a1 + t * (a2 + a3 * t)) * exp( -x * x); }

    John> Hope it helps...

Numerical recipes has a very accurate approximation, which I think they
call erfcc.  It's only a few lines -- you can type it in from the book.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019