Problems displaying values with units; math with values that have units generally

You could use a custom “To decide” phrase to wrap the functions which are defined as real-to-real in the Standard Rules in order to use them for temperatures.

One way to do that would be “quasi-functional-programming style” by parameterizing the phrase with the function (which is a phrase itself), like this:

To decide which temperature is the result of (F - a phrase real number -> real number) of (T - a temperature):
	let temp-as-real be T divided by 1 degree centigrade;
	let r be F applied to temp-as-real;
	let result be r multiplied by 1 degree centigrade;
	decide on result.

Then you could write elsewhere:

When play begins:
	let temp be 8.575 degrees Celsius;
	let minus-temp be -20 degrees Celsius;
	say "temp is [temp].";
	say "The floor of temp is [result of floor function of temp].";
	say "The ceiling of temp is [result of ceiling function of temp].";
	say "The square of temp is [result of rsqr function of temp].";
	say "The square root of temp is [result of root function of temp].";
	say "The absolute of minus-temp is [result of abs function of minus-temp].".

The names of the functions are defined in the Standard Rules, “Section SR5/2/4a - Values - Real Arithmetic (for Glulx only)”, in the lines like “(this is the ... function)”.

See chapter 22.3 “Phrases as values” for the general idea.

It would of course be better if we could also express this in a type-generic way, not just for each kind of value like temperature separately.
Something like: “To decide which K is the result of (F - a phrase real number -> real number) of (original - arithmetic value of kind K):”, as is described in chapter 22.7 “Kind variables”.

But I haven’t found an elegant solution to do the latter in conjunction with the unit conversion, because instead of doing “let temp-as-real be T divided by 1 degree centigrade;” like we did above, we would of course now need to use the correct unit for the kind of value K, and I didn’t see an obvious way to do this. But I might easily have overlooked something, of course.

Basically, instead of the “default value of K” (which is 0 or 0.0C etc. for the numerical kinds of values), we would need the multiplicative identity or neutral element of K (in other words, the equivalent of 1 expressed in K).