Skip to content

Units_divide(u, u) and Units_power(u, 0) do not reduce to dimensionless #22

Description

@cpiker

Dividing a unit by itself, or raising one to the zeroth power, builds a unit string with
zero exponents instead of returning UNIT_DIMENSIONLESS, furthermore the string it
returns can't be parsed.

das_units a = Units_fromStr("V/m");
das_units d = Units_divide(a, a);   /* "V**0 m**0", not UNIT_DIMENSIONLESS */
das_units p = Units_power(a, 0);    /* same */

Both calls report:

ERROR: Error parsing units string 'V**0 m**0' at byte number 4
       (reported from das3/units.c:662, _Units_strToComponents)

and then return a usable-looking string pointer anyway. Units_reduce() on the
result logs a second error and returns the same string.

Expected results:

  1. zero-exponent components should drop out of the result.
  2. das2C shouldn't return strings it can't parse.

Where to look: das3/units.c, Units_divide() down into _Units_strToComponents()
near line 662, also check Units_power()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions