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