Units package (was Method names)

stan at stanheckman.com stan at stanheckman.com
Wed Nov 18 02:21:55 UTC 1998


A units package for squeak is available at
http://stanheckman.com/a/98h/glimpsedotter/ASqueakUnitsPackage.st 

This package defines a bunch of objects in the new method category
"Numeric-Units", adds one method to Number
(adaptToDimensionedNumber:andSend:), and adds one dictionary to
the global namespace (BasisUnits).

Here's an example cut and pasted from a workspace. Line's with a
space at the beginning are the output of "printIt" on the preceding
line.

"Put units into global namespace"
BasisUnit loadBasisUnitsIntoSmalltalk.

"SpeedOfSound"
boltzmannConstant := 1.38e-23 * Joule / Kelvin.
 1.38e-23 joules per kelvin
nitrogenAtomMass := 14 * AtomicMassUnit.
 14.00000000000004 atomic mass units
oxygenAtomMass := 16 * AtomicMassUnit.
nitrogenMoleculeMass := 2 * nitrogenAtomMass.
oxygenMoleculeMass := 2 * oxygenAtomMass.
airMoleculeMass := 0.8 * nitrogenMoleculeMass + (0.2 * oxygenMoleculeMass).
 28.8 atomic mass units
airTemperature := 75 * Fahrenheit.
 75.0 fahrenheit
soundSpeed := ((7/5) * boltzmannConstant * airTemperature 
	/ airMoleculeMass) sqrt
 346.465447053216 meters per second

"height of mountains"
pi := Float pi.
vacuumPermittivity := 8.85419e-12 * Farad / Meter.
planckConstant := 6.626e-34 * Joule * Second.
protonMass := 1.00728 * AtomicMassUnit.
electronMass := protonMass / 1836.15.
electronCharge := 1.60218e-19 * Coulomb.
hbar := planckConstant / (2 * pi).
e2 := electronCharge squared / (4 * pi * vacuumPermittivity).

hydrogenRadius := 4 * pi * vacuumPermittivity * hbar squared / 
	(electronMass * electronCharge squared).
 5.29160925619361e-11 meters
hydrogenIonizationEnergy := electronMass * e2 squared / (2 * hbar squared).
 2.17994806928187e-18 joules
protonsPerRockMolecule := 50.
 50
massOfMolecule := protonsPerRockMolecule * protonMass.
 50.36400000000015 atomic mass units
gravitationalAcceleration := 9.8 * Meter / Second squared.
 9.8 meters per second squared
meltingEnergyPerMolecule := hydrogenIonizationEnergy / 100.
 2.17994806928187e-20 joules
maximumMountainHeight := meltingEnergyPerMolecule / 
	(gravitationalAcceleration * massOfMolecule).
 26598.09072963288 meters
maximumMountainHeight useUnits: Mile.
 16.52728734790877 miles

BasisUnit unloadBasisUnitsFromSmalltalk

This package consists of my own work, which I'm giving to the public
domain, and one routine based on Kurt Hebel's
(hebel at uinova.cerl.uiuc.edu) arithmetic package from the
smalltalk archive at 
ftp://st.cs.uiuc.edu/pub/Smalltalk/st80_r4/arithmetic.st. 
Kurt's package has no copyright notice, so he presumably still has
copyright; if you want to do anything commercial with this package,
you should either talk to Kurt or replace the gaussian elimination
routine.

-- 
Stan





More information about the Squeak-dev mailing list