[R] 0/0, R segfaults

Xing Qiu qiuxing at yahoo.com
Fri Aug 19 21:27:34 CEST 2005


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:

> 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:
> 
> >
> > 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.
> >
> >> 0/0
> > [1] NaN
> >>
> >
> > No problem on Debian 'testing' with R 2.1.1. You may want to try
> a different
> > libc.
> >
> > Dirk
> >
> > -- 
> > Statistics: The (futile) attempt to offer certainty about
> uncertainty.
> >         -- Roger Koenker, 'Dictionary of Received Ideas of
> Statistics'
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics, 
> http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>




More information about the R-help mailing list