Next: , Previous: , Up: Unit Expressions   [Contents][Index]

5.5 Previous Result

You can insert the result of the previous conversion using the underscore (‘_’). It is useful when you want to convert the same input to several different units, for example

You have: 2.3 tonrefrigeration
You want: btu/hr
        * 27600
        / 3.6231884e-005
You have: _
You want: kW
        * 8.0887615
        / 0.12362832

Suppose you want to do some deep frying that requires an oil depth of 2 inches. You have 1/2 gallon of oil, and want to know the largest-diameter pan that will maintain the required depth. The nonlinear unit ‘circlearea’ gives the radius of the circle (see Other Nonlinear Units, for a more detailed description) in SI units; you want the diameter in inches:

You have: 1|2 gallon / 2 in
You want: circlearea
        0.10890173 m
You have: 2 _
You want: in
        * 8.5749393
        / 0.1166189

In most cases, surrounding white space is optional, so the previous example could have used ‘2_’. If ‘_’ follows a non-numerical unit symbol, however, the space is required:

You have: m_
Parse error

When ‘_’ is followed by a digit, the operation is multiplication rather than exponentiation, so that ‘_2’, is equivalent to ‘_ * 2 rather than ‘_^2’.

You can use the ‘_’ symbol any number of times; for example,

You have: m
You want:
        Definition: 1 m
You have: _ _
You want:
        Definition: 1 m^2

Using ‘_’ before a conversion has been performed (e.g., immediately after invocation) generates an error:

You have: _
No previous result; '_' not set

Accordingly, ‘_’ serves no purpose when units is invoked non-interactively.

If units is invoked with the --verbose option (see Invoking Units), the value of ‘_’ is not expanded:

You have: mile
You want: ft
        mile = 5280 ft
        mile = (1 / 0.00018939394) ft
You have: _
You want: m
        _ = 1609.344 m
        _ = (1 / 0.00062137119) m

You can give ‘_’ at the ‘You want: prompt, but it usually is not very useful.

Next: , Previous: , Up: Unit Expressions   [Contents][Index]