14.5. Scaling and equivalents

| Chapter 14: Numbers and Equations |

| 14.5. Scaling and equivalents

As we've seen, we can provide differently scaled notations for the same unit:

> A length is a kind of value. 1m specifies a length.
> 1km specifies a length scaled up by 1000.

And this allows us to write "0.45km" instead of "450m", if we want to, both having the same effect.

Just as we can scale up, so we can also scale down:

> 1cm specifies a length scaled down by 100.

Now we have a spread of three notations, so "3cm", "0.03m" and "0.00003km" all mean the same thing. But something quite interesting happened at the same time: Inform realised that we want to know lengths to a greater accuracy than just a whole number of meters.

We sometimes have to remember that all of these values are stored exactly as integers. If we want to resolve down to very small values, that reduces the size of the largest value we can have. For instance, with the Glulx format setting, writing just

> A length is a kind of value. 1m specifies a length.

gives us a range of 1m up to 2147483647m, which is plenty - it's about six times the distance from the Earth to the Moon. Going down to centimeters:

> A length is a kind of value. 1m specifies a length. 1cm specifies a length scaled down by 100.

gives us instead 1cm up to 21474836.47m, which is still enough to represent any possible distance on the Earth's surface. For instance, London to Sydney is about 17000000m.

Left to itself, Inform choose the scaling for a unit so that it can represent exactly 1 of the smallest notation - so in our example Inform resolves down to 0.01m, not 1m, in order that it can represent 1cm accurately. But we can also fix the scaling ourselves:

> A length is a kind of value. 1m specifies a length scaled at 10000.

Notice "scaled at", not "scaled down" or "scaled up" - this is now the first notation for length, so there's no existing notation which it could scale up or down. Anyway, now the range is 0.0001m, the width of a human hair, up to 214748.3647m, which is about 130 miles. (The Kinds index automatically keeps track of the range of values represented exactly.)

Finally, for a really deluxe kind of value, we can also provide "equivalent" notations. The idea here is that we might want both miles and kilometers to work, even though they aren't direct scalings of each other. We can only do this approximately, but:

> 1 mile specifies a length equivalent to 1609m.

Equivalent notations are never normally used in printing values back (but see the next section) - we wouldn't want Inform to print a sequence of values such as "1.6km", "1.65km", "1.056 miles", ... in an effort to be helpful.

Previous | Contents | Next