ISSUE 59

Number 59
Category errata
Synopsis chi_square function is wrong
State lrmdraft
Class errata-simple
Arrival-DateNov 21 2001
Originator
Release 2001b: 17.9.3
Environment
http://boydtechinc.com/btf/archive/btf_1998/0194.html
Description
John wrote:

The IEEE 1364-2001 manual lists the "C" source code for the $dist_chi_square system task in section

"17.9.3 Algorithm for probabilistic distribution functions" on page 319 and 320.

It appears that the "C" code on page 320 for $dist_chi_square is an incorrect cut

and paste from another portion of the "C" code.


John,

You seem to be correct.

The original chi_square code as submitted by Adam Krolnik on 27 May 98,
from Cadence code submitted by Tom Fitzpatrick:

static double
chi_square(seed,deg_of_free)
long *seed,deg_of_free;
{
double x;
long k;
if(deg_of_free % 2)
{
x = normal(seed,0,1);
x = x * x;
}
else
{
x = 0.0;
}
for(k = 2;k <= deg_of_free;k = k + 2)
{
x = x + 2 * exponential(seed,1);
}
return(x);
}


Interesting, in the review of Draft 5, Anne Harris (comment EC-30) spotted a problem here.
It seems that in Draft 6, it was either corrected incompletely or wrong.
Fix

In 17.9.3, replace chi_square function text with the
following:

static double
chi_square(seed,deg_of_free)
long *seed,deg_of_free;
{
    double x;
    long k;
    if(deg_of_free % 2)
    {
        x = normal(seed,0,1);
        x = x * x;
    }
    else
    {
        x = 0.0;
    }
    for(k = 2;k <= deg_of_free;k = k + 2)
    {
        x = x + 2 * exponential(seed,1);
    }
    return(x);
}

Audit-Trail
Unformatted
John Williamson <john@simucad.com>

Hosted by Boyd Technology