Unidata / UDUNITS-2

API and utility for arithmetic manipulation of units of physical quantities
http://www.unidata.ucar.edu/software/udunits
Other
62 stars 36 forks source link

Dividing "mm2 day-2" by itself produces "1 1" #52

Closed djkirkham closed 6 years ago

djkirkham commented 6 years ago
#include <stdio.h>
#include "udunits.h"

int main()
{
    ut_system* sys = ut_read_xml(NULL);
    ut_unit* u = ut_parse(sys, "mm2 day-2", UT_ASCII);

    u = ut_divide(u, u);

    char buf[128];
    ut_format(u, buf, 128, UT_ASCII);
    printf("%s\n", buf);
}

Output:

1 1

However, this unit doesn't compare equal to either "1" or "1 1" defined with:

ut_unit* one = ut_parse(sys, "1", UT_ASCII);
ut_unit* one_one = ut_parse(sys, "1 1", UT_ASCII);
semmerson commented 6 years ago

This was due to a bug in the UDUNITS-2 library. It should be fixed in the latest release (2.2.26).