[ANN] Units registered at SqueakMap

Marcus Denker marcus at ira.uka.de
Mon Mar 8 15:22:42 UTC 2004


I've registered a mcz package of Helge Horch's port of Andrew Brault 
Units package
on SqueakMap:

The Units package allows you to represent, convert, and perform 
arithmetic with physical unit values (e.g. distances, velocities, 
accelerations, etc).

  There is not much formal documentation, but most of the classes in 
this package have comments. The most important methods are those in 
Unit and UnitValue. You should look through all those.

  To add your own units, see the classes BaseUnit, DerivedUnit, 
NamedUnit, and PrefixedUnit, and look through the initialization code. 
You should duplicate what is done there to add your own units. Remember 
to send Unit initialize to make your changes take effect.

  Note that you can send  Unit printAbbreviated: true  or  Unit 
printAbbreviated: false  to control how units print.

  Here is some example code:

'Create unit values by sending #units: to a number.'
2 units: #inches.
   2 inches

'You can add, divide, multiply, and subtract unit values.'
(2 units: #inches) / (3 units: #seconds).
   (2/3) inches per second

'Adding or subtracting units does appropriate conversions.'
(14 units: #feet) + (10 units: #meters).
   46.8083989501312 feet

'You can also explicitly convert values.'
(15 units: #miles) / (1 units: #hours)
         convertTo: (Unit meters / Unit seconds).
   6.7056 meters per second

'You can use 'derived' units such as the newton.'
3 units: #newtons.
   3 newtons

'You can expand such a value into base SI units.'
(3 units: #newtons) baseUnits.
   3000 gram meters per square second

'To see kilograms rather than grams, factor with respect to kilograms.'
(3 units: #newtons) factor: Unit kilograms.
   3 kilogram meters per square second

'Unit values can also be compared (provided they are dimensionally 
consistent.'
(1 units: #inches) < (3 units: #centimeters).
   true

"Creating additional units is easy:"
| microfortnight |
microfortnight := PrefixedUnit
         prefixName: 'micro'
         unit: (DerivedUnit
                         abbreviation: 'FN'
                         name: 'fortnight'
                         pluralName: 'fortnights'
                         value: (14 units: #days)).
(1 units: microfortnight) baseUnits "value asFloat"
   (756/625) seconds


--
Marcus Denker marcus at ira.uka.de



More information about the Squeak-dev mailing list