Re: [R] Interesting quirk with fractions and rounding / using == for floating point

2017-04-23 Thread J C Nash
Thanks Richard. I've some stuff too, but I need to look it up. A few years ago I built a small test spreadsheet for Gnumeric when working with Jody Goldberg. In the early 2000s, Jody contacted R (I think Duncan Murdoch) to ask if it was OK for Gnumeric to use R's distribution function

Re: [R] Interesting quirk with fractions and rounding / using == for floating point

2017-04-23 Thread Richard M. Heiberger
John, I would be happy to participate in designing the test suite you suggest. About a year ago I revised FAQ 7.31, based on my talk at the Aalberg R conference. It now points, in addition to the Goldberg paper that has been referenced there for a long time, to my appendix on precision. Here is

Re: [R] Interesting quirk with fractions and rounding / using == for floating point

2017-04-23 Thread J C Nash
Yes. I should have mentioned "optimizing" compilers, and I can agree with "never trusting exact equality", though I consider conscious use of equality tests useful. Optimizing compilers have bitten me once or twice. Unfortunately, a lot of floating-point work requires attention to detail. In the

Re: [R] Interesting quirk with fractions and rounding / using == for floating point

2017-04-23 Thread peter dalgaard
> On 23 Apr 2017, at 14:49 , J C Nash wrote: > > > So equality in floating point is not always "wrong", though it should be used > with some attention to what is going on. > > Apologies to those (e.g., Peter D.) who have heard this all before. I suspect > there are many

Re: [R] Interesting quirk with fractions and rounding / using == for floating point

2017-04-23 Thread J C Nash
For over 4 decades I've had to put up with people changing my codes because I use equalities of floating point numbers in tests for convergence. (Note that tests of convergence are a subset of tests for termination -- I'll be happy to explain that if requested.) Then I get "your program isn't

Re: [R] Interesting quirk with fractions and rounding

2017-04-22 Thread Paul Johnson
On Apr 21, 2017 12:01 PM, "JRG" wrote: A good part of the problem in the specific case you initially presented is that some non-integer numbers have an exact representation in the binary floating point arithmetic being used. Basically, if the fractional part is of the form

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread Hervé Pagès
On 04/21/2017 02:03 PM, (Ted Harding) wrote: I've been following this thread with interest. A nice collection of things to watch out for, if you don't want the small arithmetic errors due to finite-length digital representations of fractions to cause trouble! However, as well as these small

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread Ted Harding
I've been following this thread with interest. A nice collection of things to watch out for, if you don't want the small arithmetic errors due to finite-length digital representations of fractions to cause trouble! However, as well as these small discrepancies, major malfunctions can also result.

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread JRG
t; do not encounter this behaviour as Excel silently rounds all your >> calculations and makes approximate comparison without telling it does so. >> Therefore most people usually do not have any knowledge of floating point >> numbers representation. >> >> Cheers &g

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread Hervé Pagès
nson Sent: Thursday, April 20, 2017 11:56 PM To: R-help <r-help@r-project.org> Subject: [R] Interesting quirk with fractions and rounding Hello, R friends My student unearthed this quirk that might interest you. I wondered if this might be a bug in the R interpreter. If not a bug, it cert

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread Jeff Newmiller
son without telling it does >so. >> Therefore most people usually do not have any knowledge of floating >point >> numbers representation. >> >> Cheers >> Petr >> >> -Original Message- >> From: R-help [mailto:r-help-boun...@r-project.or

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread George Trojan - NOAA Federal
any knowledge of floating point *>>* numbers representation. *>>>>* Cheers *>>* Petr *>>>>* -Original Message----- *>>* From: R-help [mailto:r-help-bounces at r-project.org <https://stat.ethz.ch/mailman/listinfo/r-help>] On Behalf Of Pau

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread Bert Gunter
ore most people usually do not have any knowledge of floating point >> numbers representation. >> >> Cheers >> Petr >> >> -Original Message- >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul >> Johnson >> Sent:

Re: [R] Interesting quirk with fractions and rounding

2017-04-21 Thread Paul Johnson
nt > numbers representation. > > Cheers > Petr > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul > Johnson > Sent: Thursday, April 20, 2017 11:56 PM > To: R-help <r-help@r-project.org> > Subject: [R] Interestin

Re: [R] Interesting quirk with fractions and rounding

2017-04-20 Thread PIKAL Petr
numbers representation. Cheers Petr -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Johnson Sent: Thursday, April 20, 2017 11:56 PM To: R-help <r-help@r-project.org> Subject: [R] Interesting quirk with fractions and rounding Hello, R frien

Re: [R] Interesting quirk with fractions and rounding

2017-04-20 Thread Hervé Pagès
State Department of Social and Health Services -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Johnson Sent: Thursday, April 20, 2017 2:56 PM To: R-help Subject: [R] Interesting quirk with fractions and rounding Hello, R friends My student unearth

Re: [R] Interesting quirk with fractions and rounding

2017-04-20 Thread William Dunlap via R-help
Use all.equal(tolerance=0, aa, bb) to check for exact equality: > aa <- 100*(23/40) > bb <- (100*23)/40 > all.equal(aa,bb) [1] TRUE > all.equal(aa,bb,tolerance=0) [1] "Mean relative difference: 1.235726e-16" > aa < bb [1] TRUE The numbers there are rounded to 52 binary

Re: [R] Interesting quirk with fractions and rounding

2017-04-20 Thread Michael Hannon
n > > Daniel Nordlund, PhD > Research and Data Analysis Division > Services & Enterprise Support Administration > Washington State Department of Social and Health Services > > >> -Original Message----- >> From: R-help [mailto:r-help-boun...@r-project.org

Re: [R] Interesting quirk with fractions and rounding

2017-04-20 Thread Nordlund, Dan (DSHS/RDA)
Data Analysis Division Services & Enterprise Support Administration Washington State Department of Social and Health Services > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul > Johnson > Sent: Thursday, April 20, 2017 2:56 P

[R] Interesting quirk with fractions and rounding

2017-04-20 Thread Paul Johnson
Hello, R friends My student unearthed this quirk that might interest you. I wondered if this might be a bug in the R interpreter. If not a bug, it certainly stands as a good example of the dangers of floating point numbers in computing. What do you think? > 100*(23/40) [1] 57.5 > (100*23)/40