R-alpha: Nasty Arithmetic Bug

Ross Ihaka (ihaka@stat.auckland.ac.nz)
Thu, 21 Nov 1996 12:43:04 +1300 (NZDT)


From: Ross Ihaka <ihaka@stat.auckland.ac.nz>
Date: Thu, 21 Nov 1996 12:43:04 +1300 (NZDT)
Message-Id: <199611202343.MAA23464@stat13.stat.auckland.ac.nz>
To: r-testers@stat.math.ethz.ch
Subject: R-alpha: Nasty Arithmetic Bug

A rather nasty bug crept in in 0.13.  Mathematical functions of one
argument return random values when passed an NA.  This is because of a
missing else clause in the function "math1" in src/main/arithmetic.c
The corrected function should read.

static void math1(double (*f) (), double * x, double * y, int n)
{
        int i;

        for (i = 0; i < n; i++) {
                if (FINITE(y[i])) {
                        x[i] = MATH_CHECK(f(y[i]));
                        if(!FINITE(x[i])) {
                                x[i] = NA_REAL;
                                naflag = 1;
                        }
                }
		else x[i] = NA_REAL;	/* MISSING ELSE CLAUSE */
        }
}

Ross
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-