I have another units-related problem which I’ve half-solved, and I’m looking for a better solution.
The simulation I’m working on has, as you might imagine, a number of values with units (temperature, volume, etc), all floating-point, and sometimes their mantissas get quite long. For the sake of players, I would like to shorten these numbers when displayed, but it appears that the many of Inform’s functions for handling numbers only know how to handle what Inform calls real numbers and not values with units.
E.g.
"Printing Values With Units Test" by Kevin Riggle
[Temperature - adapted from Metric Units by Graham Nelson]
Temperature is a kind of value.
The specification of temperature is "Used to measure how hot or cold
something is. (Note that Inform writes '1 C' for one coulomb, and '1C' for
one degree centigrade.)"
1.0C (in US units, in C) or 1 degree centigrade (in degrees centigrade,
singular) or 2 degrees centigrade (in degrees centigrade, plural) or 1 degree
Celsius (in degrees Celsius, singular) or 2 degrees Celsius (in degrees
Celsius, plural) specifies a temperature.
When play begins:
let T be 8.575 degrees Celsius;
say "The temperature of T is [T][line break]";
say "The temperature of T to the nearest whole number is [T to the nearest whole number][line break]".
Example Location is a room.
This throws a compile-time error, You wrote 'say "The temperature of T to the neares [...] nearest whole number][line break]"' , which I tried to match against several possible phrase definitions. None of them worked.
where it expects a real number
instead.
The hackish workaround is to remove the units, so e.g. T divided by 1 degree Centigrade to the nearest whole number
works, albeit then requiring me to add the appropriate units back to the displayed output by hand. But for more complicated units this gets increasingly lengthy and seems like it shouldn’t be necessary. (The same problem afflicts mathematical functions like the floor
function which really should work, and adding and removing units in the middle of a complex equation gets ugly.)
Is there a better answer here?