Skip to content
Back to formatted view

Raw Message

Message-ID: <4272119E.60207@statistik.uni-dortmund.de>
Date: 2005-04-29T10:51:10Z
From: Uwe Ligges
Subject: accuracy of test cases
In-Reply-To: <8b5c2a6ed1890c8ab01506efc69b92db@soc.soton.ac.uk>

Robin Hankin wrote:

> Hi
> 
> I have several methods for evaluating a function.  The methods are 
> algebraically
> identical but use different numerical techniques. The different methods 
> work
> better (converge faster, etc) in different parts of the function's domain.
> 
> I am compiling a test suite for a package, and would like to verify that 
> the
> different methods return approximately identical results.
> 
> Toy example follows:
> 
> 
> R> f1 <- function(x){ (x-1)*(x+1)}
> R> f2 <- function(x){x^2-1}
> R> x <- pi+100i
> R> abs(f1(x) - f2(x))
> [1] 9.298027e-12
> R> stopifnot(abs(f1(x)-f2(x)) < 1e-11)
> 
> Observe that f1() should be identically equal to f2(); any differences 
> are due to
> rounding errors (needless to say, the real examples are more complex, with
> larger errors).
> 
> My question is, I am unhappy about the numerical value of the tolerance 
> used in the last line.
> The tolerance should be as small as possible, but If I make it too 
> small, the test may fail
> when executed on a machine with different architecture from mine.
> 
> How do I deal with this?

See ?all.equal

Uwe Ligges


> 
> 
> -- 
> Robin Hankin
> Uncertainty Analyst
> Southampton Oceanography Centre
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
> 
> ______________________________________________
> 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