Re: [udunits] Less pernickety version of ut_compare() ?

Bruno,

Interesting idea. I've added it to the list of issues at the UDUNITS GitHub
site <https://github.com/Unidata/LDM/issues>. You should go there and
subscribe to the issue.

I suppose a ut_tolerant_compare() function could first test to see if the
units are compatible and, if they are, convert values in one unit to the
other to determine if they are close to one another.

Why don't you post your ut_tolerant_compare() function to the GitHub site.

Regards,
Steve Emmerson

On Tue, Aug 11, 2015 at 6:34 AM, PIGUET Bruno <bruno.piguet@xxxxxxxx> wrote:

> Hi,
>
>     I found the ut_compare() function, as currently existing the the
> udunits2 library,  to be too strict for my needs.
>
>     In particular, for some units, the comparison between the original
> unit and a back-and-forth transformation to text expression fails.
>     In other words :  for some values of unit, ut_compare(unit,
> (ut_parse(ut_format(unit))) != 0.
>
>     I know that a decimal textual representation of a real number cannot
> be exact, but I believe that we can safely assume that two units whose
> relative difference is less than 10^-8 or 10^-10 are identical.
>     So, I wrote my own, more tolerant, ut_compare function (see attached
> source code).
>
>      My questions are :
>                  - is this pernickety behaviour intended, or did someone
> just wrote the test "a==b" for floating-point values instead of the usual
> approximate test ?
>                  - Am I the only one interested in a more lenient version
> of ut_compare() ? Would it be a good idea to add a ut_tolerant_compare()
> function to the udunits2 library ?
>
> Regards,
>
> Bruno.
>
> --
> Bruno Piguet
> Météo-France
> Équipe GMEI/TRAMM
> CNRM/GAME, UMR3589 CNRS/Météo-France
> Fixe : +33 561079659
> Fax : +33 561079627
> Postal : 42 Av. G. Coriolis
> 31057 Toulouse CEDEX 1
>
>
>
> _______________________________________________
> udunits mailing list
> udunits@xxxxxxxxxxxxxxxx
> For list information, to unsubscribe, or change your membership options,
> visit: http://www.unidata.ucar.edu/mailing_lists/
>
>
  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the udunits archives: