[Bioperl-l] evalues/floating point tests

Chris Fields cjfields at illinois.edu
Sun Jan 18 22:51:42 UTC 2009


On Jan 18, 2009, at 6:01 AM, Sendu Bala wrote:

> 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().

Yes, that's partly why I suggested it.  That's most descriptive of  
what we are doing with this method, 'is float $ev1 eq float $ev2'.

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

Sorry, no disrespect to you or Mark but I don't agree. 'Is as float'  
doesn't come across to me as an equality test, it almost sounds like a  
role/interface check.

>> 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.

I see what you're saying in this case.  We can go back to the simpler  
is_float() if everyone agrees.  Just want to have something decided so  
we can move on.

> 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.

I understand the sentiment about extending is() but I'm not convinced  
it makes sense for a specific case such as this.  I agree with the  
second sentiment; extending is() may be more dangerous and prone to  
subtle issues, such as the regex above not matching '1.23e-12'. Yes, I  
know, you didn't test it. ;>

And, if we ever change our minds it would be very easy to just  
delegate to is_float().

$e_num = qr/something that matches just floats/;
sub is {
    my ($val1, $val2, @args) = @_;

    if ($val1 && $val2 && $val1 =~ /$e_num/ && $val2 =~ /$e_num/) {
        return is_float($val1, $val2, @args);
    } else {
        return SUPER::is($val1, $val2, @args);
    }
}

chris




More information about the Bioperl-l mailing list