Wireshark-dev: Re: [Wireshark-dev] Sorting floats?

From: "Maynard, Chris" <Christopher.Maynard@xxxxxxxxx>
Date: Tue, 17 Feb 2009 11:37:00 -0500
Title: Sorting floats?

Not knowing the test data which makes it fails, I can only suggest a couple of things:

 

First, why consider floats equal if their difference is less than some tolerance?  Why not just compare them and let the natural comparison dictate less than, equal or greater than?  i.e.,

 

if (f1 == f2)

    return 0;

if (f1 < f2)

    return -1;

return 1;

 

Also, is it possible that atof() is failing but that the error is not being detected and that is causing problems?  If so, try strtod() instead and add code to handle the errors?

 

- Chris

 

 

From: wireshark-dev-bounces@xxxxxxxxxxxxx [mailto:wireshark-dev-bounces@xxxxxxxxxxxxx] On Behalf Of Anders Broman
Sent: Tuesday, February 17, 2009 3:42 AM
To: Developer support list for Wireshark
Subject: [Wireshark-dev] Sorting floats?

 

Hi,
The following code in rtp_analysis.c
        case 4:
                f1=atof(text1);
                f2=atof(text2);
                if (fabs(f1-f2)<0.0000005)
                        return 0;
                if (f1<f2)
                        return -1;
                return 1;
Is used to sort floats but it seems not to give the right result. Does any one know how to fix it?

Regards
Anders

CONFIDENTIALITY NOTICE: The contents of this email are confidential
and for the exclusive use of the intended recipient. If you receive this
email in error, please delete it from your system immediately and 
notify us either by email, telephone or fax. You should not copy,
forward, or otherwise disclose the content of the email.