Previous: Complicated Unit Expressions, Up: Unit Expressions

5.7 Backwards Compatibility: ‘*’ and ‘-

The original units assigned multiplication a higher precedence than division using the slash. This differs from the usual precedence rules, which give multiplication and division equal precedence, and can be confusing for people who think of units as a calculator.

The star operator (‘*’) included in this units program has, by default, the same precedence as division, and hence follows the usual precedence rules. For backwards compatibility you can invoke units with the --oldstar option. Then ‘*’ has a higher precedence than division, and the same precedence as multiplication using the space.

Historically, the hyphen (‘-’) has been used in technical publications to indicate products of units, and the original units program treated it as a multiplication operator. Because units provides several other ways to obtain unit products, and because ‘-’ is a subtraction operator in general algebraic expressions, units treats the binary ‘-’ as a subtraction operator by default. For backwards compatibility use the --product option, which causes units to treat the binary ‘-’ operator as a product operator. When ‘-’ is a multiplication operator it has the same precedence as multiplication with a space, giving it a higher precedence than division.

When ‘-’ is used as a unary operator it negates its operand. Regardless of the units options, if ‘-’ appears after ‘(’ or after ‘+’ then it will act as a negation operator. So you can always compute 20 degrees minus 12 minutes by entering ‘20 degrees + -12 arcmin’. You must use this construction when you define new units because you cannot know what options will be in force when your definition is processed.