4. What FURY refuses
FURY checks the units at every operation that needs them consistent, and stops the program at the first inconsistency: it prints an error on the standard error and ends with error stop, exit status 1. A wrong number never leaves the operation.
The program of this chapter takes a scenario from the command line; the quantities are
length = 3._R8P * metre
other_length = 2._R8P * metre
time = 2._R8P * secondSums and differences
A sum, or a difference, needs the same units on both sides:
total = length + time$ tutorial_4 add
error: cannot add "+3.0 m [length]" and "+2.0 s [time]"
[exit status 1]Products and quotients are always allowed: their unit is derived (chapter 3).
Assignments
A quantity that has a unit keeps it: assigning it a quantity with another unit is an error.
total = length
total = time$ tutorial_4 assign
error: cannot assign "+2.0 s [time]" to "+3.0 m [length]"
[exit status 1]The first assignment gives total the unit m; the second one would silently change it into a time. To reuse a variable for another unit, unset it first:
total = length
call total%unset
total = time
print '(A)', total%stringify(format='(F3.1)')$ tutorial_4 reuse
2.0 sThe same holds for units: a uom64 that has a unit is assigned only the same unit, unless it is unset.
Definitions
The dimensions of a symbol must have its exponent: a frequency in s-1 has dimensions time-1, not time-2.
frequency = uom64('Hz = s-1 [time-2]')$ tutorial_4 parse
error: cannot parse "Hz = s-1 [time-2]": the exponent of the dimensions "time-2" differs from the one of the symbol "Hz"
[exit status 1]Comparisons
== and /= compare the magnitudes and the units; has_same_unit compares the units only:
print '(L1)', length == 3._R8P * metre
print '(L1)', length /= other_length
print '(L1)', length%has_same_unit(other_length)
print '(L1)', length%has_same_unit(time)$ tutorial_4 compare
T
T
T
FWhat you learned
Sums, differences, assignments and definitions are checked; an inconsistency stops the program with exit status 1; unset frees a variable for another unit. Reference: Errors.
Next: 5. Conversions.