[Bioperl-l] evalues/floating point tests

Sendu Bala bix at sendu.me.uk
Sun Jan 18 07:01:48 EST 2009

Chris Fields wrote:
> is_float_eq()?

The 'is' obviates the need for the 'eq'. On the other hand there's 
precedent for this, since is() actually calls is_eq().

> On Jan 17, 2009, at 8:44 PM, Mark A. Jensen wrote:
>> how bout is_asfloat() ?

This is better. However...

> I thought the same thing at first, but (at least to me) is_float
> sounds more like a boolean test on whether the scalar value passed is
> a float rather than a comparison checking whether two floats are
> equal.

I understand that, but the naming convention is already like that. 
is_deeply() doesn't test if both values are 'deep', it tests if they are 
'is' (are equal) in a deep way. is_float() would test if they are 'is' 
(are equal) in a float way. Yeah, grammatically it is all a mess, but to 
me this seems the most consistent.

The alternative, which may at the same time may be safer (the test 
writer doesn't need to remember to use a special function) and more 
dangerous (the regex matches something it shouldn't?), is to simply 
override is():

my $e_num = '^\de-\d+$';
sub is {
     my ($val1, $val2, @args) = @_;

     if ($val1 && $val2 && $val1 =~ /$e_num/ && $val2 =~ /$e_num/) {
         $val1 = sprintf("%g", $val1);
         $val2 = sprintf("%g", $val2);

     return SUPER::is($val1, $val2, @args);

Or something like that. I didn't try it.

More information about the Bioperl-l mailing list