Message-ID: <42949B11.1060505@stats.uwo.ca>
Date: 2005-05-25T15:34:41Z
From: Duncan Murdoch
Subject: precision problem
In-Reply-To: <3f87cc6d05052507083041d095@mail.gmail.com>
Omar Lakkis wrote:
>I have prices that I am finding difficult to compare with ==, > and >,
>due to precision. For example: the numbers should match, with '==',
>but they differ in the magnitude of 1e-14 due to bunch of calculations
>that I run on them. Programming with java, I am used to implementing a
>function that compares the difference between the numbers to a pre
>determined precision factor. This could be very slow when I have two
>matrices of numbers that I could otherwise compare with a simple '==',
>'>' or '<' in R.
>What is teh best solution for this problem?
>Can I control the precision of ==, > and < without having to
>reimplement the operations in a slow way?
>
The somewhat misleadingly named "all.equal()" function does what you
want for ==. For the inequalities, you may want to add some constant to
one side, e.g.
x > y-.Machine$double.eps ^ 0.5
instead of x > y.
Duncan Murdoch