Re: [Rd] bug? (PR#8074)

From: <>
Date: Wed 17 Aug 2005 - 02:59:18 GMT

G'day Paul,

>>>>> "PM" == Paul Mosquin <> writes:

    PM> Thomas, Thank you for your response.  I checked the FAQ and it
    PM> provides an example using sqrt(2) where you'd expect numerical
    PM> precision to be an issue.

You should expect numerical precision issues in all calculations involving "real" numbers in finite precision arithmetic. Perhaps the FAQ should include a link to, say:

(A copy of Goldberg's "What Every Computer Scientist Should Know About Floating-Point Arithmetic".)

    PM> I guess that I expect R to act pretty much as C or C++ would     PM> do if I were to program the same code. Well, did you? I am pretty sure that you would have the same results in C or C++, at least I do (see below). But please, don't go and fill another bug report for your C or C++ compiler when you see that it behaves the same way as R. :-)

[bossiaea:test]$ cat test1.c

  double x = 0.2;

  if( x*x == 0.04)
    printf("The numbers are equal\n");
    printf("The numbers are *NOT* equal\n");

  return EXIT_SUCCESS;
[bossiaea:test]$ gcc -o test1 test1.c
[bossiaea:test]$ ./test1
The numbers are *NOT* equal

    PM> It's a bit of a surprise that assignment of rationals, well
    PM> within precision, followed by multiplication leading to a
    PM> result well within precision picks up those extra bits along
    PM> the way.  Something to watch out for, to be sure.
No surprise at all for anybody who learned about how numbers are represented in a computer and how finite precision arithmetic works. Big hint, 0.2 is not exactly representable in a binary basis (and there have been function posted to the R mailing lists that show you the binary representation of real numbers on your machine).

Read the link above or a book on numerical analysis, e.g. Chapter 1 in


  author =       {Gentle, J. E.},
  title =        {Numerical Linear Algebra with Applications in Statistics},
  publisher =    {Springer-Verlag},
  year =         1998,
  series =       {Statistics and Computing},
  address =      {New York}



        Berwin mailing list Received on Wed Aug 17 13:02:36 2005

This archive was generated by hypermail 2.1.8 : Mon 24 Oct 2005 - 22:27:38 GMT