Bottom line up front, I’ve halfway solved my problem, but I’m curious if there’s a better solution than the one I found.
I’m working on a moderately complicated simulation in Inform (a port of this old Applesoft BASIC program, and so it seemed obvious that I would want to start from the Metric Units extension and then add US units on top as needed.
Once I started getting numbers out, though, it was clear that there was something wrong. After fixing several of the more obvious bugs, this was the one that finally stumped me:
"Coolant Heat Flow Equation test" by Kevin Riggle Include Metric Units by Graham Nelson. [Gallons] 1.0 G (in US units, in G) or 1 gallon (in gallons, singular) or 2 gallons (in gallons, plural) or 1 gal (in gals, singular) or 2 gals (in gals, plural) specifies a volume equivalent to 3.785 liters. [Volumetric flow] Volumetric flow is a kind of value. 1.0 G/day (in US units, in G/day) or 1 gallon per day (in gallons per day, singular) or 2 gallons per day (in gallons per day, plural) or 1 gal/d (in gals/d, singular) or 2 gals/d (in gals/d, plural) or 1 gal/day (in gals/day, singular) or 2 gals/day (in gals/day, plural) specifies a volumetric flow. Volumetric flow times elapsed time specifies a volume. [Foo] Foo is a kind of value. 1.0 sq gal/day (in US units, in sq gals/day) or 2 sq gals/day (in sq gals/day, plural) specifies a foo. A volume times a volumetric flow specifies a foo. When play begins: let CF be 1 gal/day; let CV be 1 gallon; let HF be CF times CV; say "The result is [HF].[line break]". Example Location is a room.
The expected result is, intuitively, 1 square gallon per day. What actually outputs is The result is 0.00379 sq gal/day.
(Gallons, squared, per day is a made-up unit but one that occurs as part of a larger formula in the source project.)
Finally getting a project that built, and looking at the Index in preparation for making this post, I discovered that Inform had developed some odd ideas about how the various units here are related, e.g.
volumetric flow x elapsed time = volume 1 G/day x 1s = 1 cu m volume x volumetric flow = foo 1 cu m x 1 G/day = 1 sq gal/day
It looks to me like Inform is assuming that everything is defined in terms of the base unit, in metric. The easy answer was to stop using the Metric Units extension completely and pull in only the definitions from it I need, so that the volumetric flow relationship winds up defined as 1 gal/day x 1s = 1 gal
, with no liter to confuse it, and probably that’s also the best answer for this particular project going forward, but the scientist in me is unsatisfied.
I think I had assumed that Inform has a much more robust idea of different systems of units than it actually has, and I’m surprised to discover that it isn’t at least picking the smallest defined unit in the same system.
Is there some way to hint to Inform that when I say, Volumetric flow times elapsed time specifies a volume
, I mean it in gallons?