Re: [R] 0/0, R segfaults

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Sat 20 Aug 2005 - 05:49:45 EST

Xing Qiu <qiuxing@yahoo.com> writes:

> 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

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

>
>
> --- Prof Brian Ripley <ripley@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@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@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@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
> >
>
> ______________________________________________
> R-help@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
>

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@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
Received on Sat Aug 20 05:55:47 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:35:16 EST