Skip to content

0/0, R segfaults

6 messages · Dirk Eddelbuettel, Brian Ripley, Xing Qiu +1 more

#
Hi, 

    I noticed that when I was conducting some calculation involving
finding correlation coeficients, R stopped abnormally. So I did some
research, and find out that 0/0 was the culprit.  For sure 0/0 is not
a valid expression, but R should give a warning, an error msg or NaN
instead of segmentation fault.

    I am using R 2.1.0 under Gentoo Linux. My GCC version is 3.3.5.

Xing
#
On 18 August 2005 at 16:01, Xing Qiu wrote:
| Hi, 
| 
|     I noticed that when I was conducting some calculation involving
| finding correlation coeficients, R stopped abnormally. So I did some
| research, and find out that 0/0 was the culprit.  For sure 0/0 is not
| a valid expression, but R should give a warning, an error msg or NaN
| instead of segmentation fault.
| 
|     I am using R 2.1.0 under Gentoo Linux. My GCC version is 3.3.5.

edd at basebud:~> R

R : Copyright 2005, The R Foundation for Statistical Computing
Version 2.1.1  (2005-06-20), ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.
[1] NaN
No problem on Debian 'testing' with R 2.1.1. You may want to try a different
libc.

Dirk
#
To expand on Dirk's answer, R relies on fairly close compliance to 
IEC60559 (aka IEEE754) arithmetic in which 0/0 = NaN.  As R is C/Fortran 
program, this is a function of your C/Fortran compilers (it is most likely 
an FPU setting controlled by the compiler than libc).  Problems in this 
area are documented in the R-admin manual.

We don't know the CPU here, so ix86 is a plausible guess.  That has a FPU
control word that determines if 0/0 is NaN or an exception.  Prior to 
glibc 2.1 it could be set by __setfpucw and R sets it if NEED___SETFPUCW
is defined (only in older Linuxen).

Other people using Gentoo are not reporting problems, so this has to be a 
very specific problem, one which is best addressed to a Gentoo list.  Try 
a very simple C program such as

#include <stdio.h>
int main()
{
    double x = 0.0;
    printf("x/x = %f\n", x/x); 
}

R is doing nothing different on my Linux box (except it arranges to print 
NaN not nan regardless of platform).
On Thu, 18 Aug 2005, Dirk Eddelbuettel wrote:

            

  
    
#
Thank you very much, I did try your simple C program and it works
without any problem.  I even tried some more sophisticated examples,
and they all print out nan instead of a segfault.

My computer has a Pentium 4 CPU, and I compiled R with the following
flags (these are just my default compiler Cflags):

-O3 -march=pentium4 -pipe -fomit-frame-pointer -ffast-math
-mfpmath=sse,387 -msse2 -mmmx
--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:

            
#
I just found out that I can do:

x <- 0/0

in my R without any problem, it is only when I was trying to print
the value of x by simply type x and return, R crashed with a sigh of
segfault .... This is so wierd. I will try to report it to the Gentoo
forum and see if any other gentoo user has the same problem.

Xing
--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:

            
#
Xing Qiu <qiuxing at yahoo.com> writes:
Get rid of those math settings. fast-math tends to break IEEE
compliance and fpmath=sse,387 is labeled experimental on the gcc man
page (as you might well have found out for yourself...). 
 
        -p