saiunit.is_unit_equal_math

saiunit.is_unit_equal_math#

saiunit.is_unit_equal_math(u1, u2)#

Check whether two units are mathematically equivalent.

Two units are mathematically equivalent when they have the same dim, scale, base, and factor — i.e. they convert quantities the same way. The display name and dispname are ignored, so e.g. metre and meter (different aliases of the SI meter) are equivalent, and a freshly-composed A * ohm is equivalent to volt.

This is the same comparison Unit.__eq__ performs (name and dispname are not part of either comparison), so is_unit_equal_math(u1, u2) and u1 == u2 agree for two Unit operands; this function additionally tolerates non-Unit arguments by returning False instead of raising.

Parameters:
  • u1 (Unit) – The units to compare.

  • u2 (Unit) – The units to compare.

Returns:

True if u1 and u2 are mathematically equivalent.

Return type:

bool

Examples

>>> import saiunit as u
>>> u.is_unit_equal_math(u.metre, u.meter)
True
>>> u.is_unit_equal_math(u.amp * u.ohm, u.volt)
True
>>> u.is_unit_equal_math(u.mV, u.volt)
False