Thanks David.  This is a nice module, but overkill for my needs and I'd
rather not make people install more CPAN modules than they have to.

Looks like the key thing is this line:

        $ok = abs($p - $q) < $epsilon;

I'll incorporate that bit into my test suite for Number::Format.

On Tue, May 5, 2009 at 12:05 PM, David Golden <xda...@gmail.com> wrote:

> On Tue, May 5, 2009 at 2:58 PM, Jonathan Leto <jal...@gmail.com> wrote:
> > I very much recommend that you look at is_similar() in
> > Math::GSL::Test, it has implemented at least a
> > few wheels that you are destined to want:
>
> Yikes.  You must have missed Test::Number::Delta when you were writing
> that.  On CPAN since 2005.  I originally called it Test::Float and got
> argued into a proper hierarchical name, which is probably why no one
> seems to know it exists.   Synopsis:
>
>  # Import test functions
>  use Test::Number::Delta;
>
>  # Equality test with default tolerance
>  delta_ok( 1e-5, 2e-5, 'values within 1e-6');
>
>  # Inequality test with default tolerance
>  delta_not_ok( 1e-5, 2e-5, 'values not within 1e-6');
>
>  # Provide specific tolerance
>  delta_within( 1e-3, 2e-3, 1e-4, 'values within 1e-4');
>  delta_not_within( 1e-3, 2e-3, 1e-4, 'values not within 1e-4');
>
>  # Compare arrays or matrices
>  @a = ( 3.14, 1.41 );
>  @b = ( 3.15, 1.41 );
>  delta_ok( \...@a, \...@b, 'compare @a and @b' );
>
>  # Set a different default tolerance
>  use Test::Number::Delta within => 1e-5;
>  delta_ok( 1.1e-5, 2e-5, 'values within 1e-5'); # ok
>
>  # Set a relative tolerance
>  use Test::Number::Delta relative => 1e-3;
>  delta_ok( 1.01, 1.0099, 'values within 1.01e-3');
>



-- 
Check out my LEGO blog at http://www.brickpile.com/
View my photos at http://flickr.com/photos/billward/
Follow me at http://twitter.com/williamward

Reply via email to