PhysicalValues/en
Expecco supports values with units to represent physical values such as length, acceleration, area, volume, mass, temperature etc.
Physical values are useful for a nicer presentation of values (eg. in a report) and to convert between unit systems (eg. metric vs. imperial vs. US).
Physical values are implemented by the underlying Smalltalk system and can be used in JavaScript and Smalltalk elementary blocks. Similar public domain packages are available for Node and Python actions - these have to be installed with "rpm"or "pip".
Inhaltsverzeichnis
Base Units[Bearbeiten]
All base units are measured in their corresponding SI standard units and print with an appropriate scaling prefix.
For example, a mass, which has a base unit of kilogram ("kg") will print itself as "kg', 'mg', 'µg' etc. depending on its magnitude. Explicit converters can be used to enforce a particular unit printing (eg. if you insist on printing a mass in pounds, in grams, etc.). See examples below on how those converters affect the printout of a value.
Base units are:
s second time m metre length kg kilogram mass A ampere electric current K kelvin temperature mol mole amount of substance cd candela luminous intensity
Derived Units[Bearbeiten]
Additional derived units are:
V volt voltage Hz hertz frequency m/s meter per second speed, velocity m/s² m/s per second acceleration m² square meter area m³ cubic meter volume pa pascal pressure w watt power N newton force J joule energy Ω ohm electric resistance C coulomb electric charge F farad electric capacitance
SI Prefix[Bearbeiten]
Numbers can be scaled by an SI prefix message. For example, without si prefix:
1 gram -> '1 g'
whereas with a 'micro' prefix:
1 micro gram -> '1 µg'
and:
1 hecto liter -> '100 liter'
Possible scaling prefixes are:
yocto 1E-24 1 / 1000000000000000000000000 zepto 1E-21 1 / 1000000000000000000000 atto 1E-18 1 / 1000000000000000000 femto 1E-15 1 / 1000000000000000 pico 1E-12 1 / 1000000000000 nano 1E-9 1 / 1000000000 micro 1E-6 1 / 1000000 milli 1E-3 1 / 1000 centi 1E-2 1 / 100 deci 1E-1 1 / 10 deca 1E+1 10 hecto 1E+2 100 kilo 1E+3 1000 mega 1E+6 1000000 giga 1E+9 1000000000 tera 1E+12 1000000000000 peta 1E+15 1000000000000000 exa 1E+18 1000000000000000000 zetta 1E+21 1000000000000000000000 yotta 1E+24 1000000000000000000000000
Unit API[Bearbeiten]
PhysicalValue instances can be created by sending the "amount:" message to a Unit.
For example:
Physics energy amount:100
generates an energy instance of 100 joule.
For the most common units, additional protocol is provided in the Number class (eg. "100 joules"). The additional protocol is described below.
When printed, physical values will scale and use an SI prefix as appropriate. Thus, by default, a value of 100 millimeter will print as "100 mm" instead of "0.1 m".
This print behavior can be changed by converting to an explicit unit via one of the "asXXX" messages listed below. However, the correct amount will be used in arithmetic operations. Thus, eg. when adding a meter with inches, the correct value will be generated, and the result will be presented in the same unit as the receiver (first operand). For example, "1 meter + 1 inch asInches" will print as meter, whereas "1 inch asInches + 1 meter" will print as inches.
Mass[Bearbeiten]
Mass is measured in units of kilogram. The following operations return an instance of a mass (i.e. a value with a unit of "Mass"):
- number kiloGram 
 Generates a mass-value of n kilograms. Same asn kilo gram.
- number gram 
 Generates a mass-value of n grams.
- number milliGram 
 Generates a mass-value of n milligrams. Same asn milli gram.
- number microGram 
 Generates a mass-value of n micrograms. Same asn micro gram.
- number pounds 
 Generates a mass-value of n pounds. A pound is 453.59237 gram.
Conversion[Bearbeiten]
- aMass asGrams 
 Returns the original mass but enforces explicit printing in grams (i.e. without any SI scaling prefix).
- aMass asMilliGrams 
 Enforces explicit printing in milligrams ("mg").
- aMass asMicroGrams 
 Enforces explicit printing in micrograms ("µg").
- aMass asKiloGrams 
 Enforces explicit printing in kilograms ("kg").
- aMass asPounds 
 Enforces explicit printing in pounds ("lb").
Length[Bearbeiten]
Length is measured in meters.
- number meter 
 Generates a length-value of n meters.
- number centiMeter 
 Generates a length-value of n centimeters. Same asn centi meter.
- number milliMeter 
 Generates a length-value of n millimeters. Same asn milli meter.
- number microMeter 
 Generates a length-value of n micrometers. Same asn micro meter.
- number nanoMeter 
 Generates a length-value of n nanometers. Same asn nano meter.
- number kiloMeter 
 Generates a length-value of n kilometers. Same asn kilo meter.
- number inch 
 Generates a length-value of n inches. An inch is 25.4 mm.
- number feet 
 Generates a length-value of n feet. A foot is 0.3048 m.
- number landMiles 
 Generates a length-value of n landMiles. A landMile is 5280 feet or 1609.344 m.
- number nauticalMiles 
 Generates a length-value of n nauticalMiles. A nauticalMile is 1852 m.
- number astronomicalUnits 
 Generates a length-value of n astronomical units. An au is 149597870.7 km.
- number lightSeconds 
 Generates a length-value of n lightseconds. An ls is 299792.458 km.
- number lightYears 
 Generates a length-value of n lightyears. An ly is 9460730472580.8 km.
- number angstrom 
 Generates a length-value of n angstroms. 1 Å = 0,1 = 10E−10 m.
Conversion[Bearbeiten]
- aLength asMeters 
 Returns the original length but enforces explicit printing in meters (i.e. prevents scaling prefix when printed).
- aLength asMilliMeters 
 Enforces explicit printing in millimeters ("mm").
- aLength asMicroMeters 
 Enforces explicit printing in micrometers ("µm").
- aLength asNanoMeters 
 Enforces explicit printing in nanometers ("nm").
- aLength asKiloMeters 
 Enforces explicit printing in kilometers ("km").
- aLength asInches 
 Enforces explicit printing in inches ("in").
- aLength asFeet 
 Enforces explicit printing in feet ("ft").
- aLength asYards 
 Enforces explicit printing in yards ("yd").
- aLength asFeetAndInches 
 Enforces explicit printing in feet and inches (inches rounded to 4 digits).
- aLength asLightYears 
 Enforces explicit printing in lightyears ("ly").
Temperature[Bearbeiten]
- number kelvin 
 Generates an temperature-value of n Kelvin.
- number degreesCelcius 
 Generates an temperature-value of n degrees Celsius.
- number degreesFahrenheit 
 Generates an temperature-value of n degrees Fahrenheit.
- number rankine 
 Generates an temperature-value of n degrees Rankine.
Conversion[Bearbeiten]
- aTemperature asFahrenheit 
 Returns the original temperature but enforces explicit printing in Fahrenheit.
- aTemperature asCelsius 
 Enforces explicit printing in degrees celsius.
Frequency[Bearbeiten]
- number hertz 
 Generates an frequency-value of n hertz.
- number kiloHertz 
 Generates an frequency-value of n kilohertz. Same asn kilo hertz.
- number megaHertz 
 Generates an frequency-value of n megahertz. Same asn mega hertz.
- number gigaHertz 
 Generates an frequency-value of n gigahertz. Same asn giga hertz.
Conversion[Bearbeiten]
- aFrequency asKiloHertz 
 Returns the original frequency but enforces explicit printing in kilohertz ("kHz").
- aFrequency asMegaHertz 
 Enforces explicit printing in megahertz ("mHz").
- aFrequency asGigaHertz 
 Enforces explicit printing in gigahertz ("gHz").
Energy[Bearbeiten]
- number joule 
 Generates an energy-value of n joule.
- number kiloJoule 
 Generates an energy-value of n kilojoule. Same asn kilo joule.
- number megaJoule 
 Generates an energy-value of n megajoule. Same asn mega joule.
- number wattHours 
 Generates an energy-value of n wattHours. Same asn watt * 1 hours.
- number kiloWattHours 
 Generates an energy-value of n kiloWattHours. Same asn kilo wattHoursand also the same asn kilo watt * 1 hours.
- number megaWattHours 
 Generates an energy-value of n megaWattHours. Same asn mega wattHoursand also the same asn mega watt * 1 hours.
- number electronVolts 
 Generates an energy-value of n electronVolts.
- number btu 
 Generates an energy-value of n BTUs (british thermal units).
- number calories 
 Generates an energy-value of n calories.
- number kiloCalories 
 Generates an energy-value of n kcal.
Converting[Bearbeiten]
- energy asElectronVolts 
 Present as electronVolts
- energy asKiloWattHours 
 Present as kiloWattHours
- energy asMegaWattHours 
 Present as megaWattHours
- energy asGigaWattHours 
 Present as gigaWattHours
- energy asBTUs 
 Present as BTUs (British Thermal Units)
- energy asCalories 
 Present as calories
- energy asKiloCalories 
 Present as kilo calories
Power[Bearbeiten]
- number watt 
 Generates a power-value of n watt.
- number kiloWatt 
 Generates a power-value of n kiloWatt. Same asn kilo watt.
- number megaWatt 
 Generates a power-value of n megaWatt. Same asn mega watt.
- number gigaWatt 
 Generates a power-value of n gigaWatt. Same asn giga watt.
Converting[Bearbeiten]
- power asKiloWattHours 
 Presents itself as kWh
- power asMegaWattHours 
 Presents itself as mWh
- area asGigaWattHours 
 Presents itself as gWh
Force[Bearbeiten]
- number newton 
 Generates a force-value of n newton.
Area[Bearbeiten]
- number squareMeter 
 Generates an area-value of n square meters.
- number hectare 
 Generates an area-value of n hectares. Same asn hecto are.
- number are 
 Generates an area-value of n ares. 1 are being 10 m².
- number squareFeet 
 Generates an area-value of n square feet. 1 sq ft being 0.0929 m².
- number acres 
 Generates an area-value of n acres. 1 acre being 4046.856 m².
Converting[Bearbeiten]
- area asSquareFeet 
 Presents itself as square feet
- area asHectare 
 Presents itself as hectare
- area asAcres 
 Presents itself as acres
Volume[Bearbeiten]
- number cubicMeter 
 Generates an volume-value of n cubic meters (1000 l).
- number liter 
 Generates an volume-value of n liters.
- number milliLiter 
 Generates a volume-value of n milliliters. Same asn milli liter.
- number hectoLiter 
 Generates a volume-value of n hectoliters. Same asn hecto liter.
- number barrel 
 Generates a volume of n barrels (oil volume measurement).
- number flozGB 
 Generates a volume of n imperial fluid ounces (0.02841 liter).
- number flozUS 
 Generates a volume of n US fluid ounces (0.02957 liter).
- number pintGB 
 Generates a volume of n imperial pints (568.26125 ml).
- number pintUS 
 Generates a volume of n US pints (473.176473 ml).
- number quartGB 
 Generates a volume of n imperial quarts (1.1365 liter).
- number quartUS 
 Generates a volume of n US quarts (946.353 ml).
- number gallonGB 
 Generates a volume of n imperial gallons (4.5461 liter).
- number gallonUS 
 Generates a volume of n US gallons (3.7854 liter).
Converting[Bearbeiten]
- volume asCubicMeters 
 Presents itself as cubic meters
- volume asFlozGB 
 Presents itself as imperial fluid ounces
- volume asFlozUS 
 Presents itself as US fluid ounces
- volume asGallonsGB 
 Presents itself as imperial gallons
- volume asGallonsUS 
 Presents itself as US gallons
- volume asHectoLiters 
 Presents itself as hectoliters
- volume asMilliLiters 
 Presents itself as milliliters
Velocity (Speed)[Bearbeiten]
- number meterPerSecond 
 Generates a velocity of n meters per second.
- number kiloMeterPerHour 
 Generates a velocity of n km per hour.
- number milesPerHour 
 Generates a velocity of n mph.
- number knots 
 Generates a velocity of n nautical miles per hour.
Converting[Bearbeiten]
- volume asKiloMetersPerHour 
 Presents itself as km/h
- volume asMilesPerHour 
 Presents itself as mph
Acceleration[Bearbeiten]
- number metersPerSecondPerSecond 
 Generates an acceleration of n m/s².
Mass Density[Bearbeiten]
This is a derived unit, which is generated when dividing a mass by a volume; eg:
10 kiloGram / 1 liter
gives
'10000 kg / m³'
Arithmetic[Bearbeiten]
Arithmetic on physical values will generate an appropriate physical value. Eg, when multiplying a velocity by a time, you will get a distances, or when dividing a distance by a time, you will get a velocity.
Acceleration[Bearbeiten]
speed = acceleration * time
1 meterPerSecondPerSecond * 10 seconds -> 10 m/s (1 meterPerSecondPerSecond distanceAfter:1 hours) -> 6480.0 km
Mass[Bearbeiten]
force = mass * acceleration
1 kg * 1 meterPerSecondPerSecond -> 1 N
Examples[Bearbeiten]
Smalltalk code + printed representation.
1 kiloGram + 10.0 gram -> '1.01 kg' 10 gram -> '10 g' 10 gram asKiloGrams -> '0.01 kg' 10 gram asMilliGrams -> '10000 mg'
1 microGram -> '1 µg' 1 micro gram -> '1 µg'
1 pound -> '453.59237 g' 1 pound asKiloGrams -> '0.45359237 kg' 1 pound asPounds -> '1.0 lb' 1 kiloGram asPounds -> '2.20462262184878 lb'
10 kiloMeters asMeters -> '10000 m' 1 micro inch -> '25.4 nm' 1.80 meter asFeetAndInches -> '5′10.866″' 1 yards -> '0.9144 m'
0 degreesCelsius -> '273.16 K' 0 degreesCelsius asFahrenheit -> '32.018 °F' 40 degreesFahrenheit -> '277.59 K' 60 degreesFahrenheit asCelsius -> '15.556 °C' 40 degreesFahrenheit asKelvin -> '277.59 K' 10 kelvin -> '10 K' 100 rankine -> '55.556 K'
1 joule asElectronVolts -> '6.24150912550149E+18 eV' 10 electronVolts -> 1.6021766208E-18 J 1000 joule asKiloWattHours -> '0.000278 kWh' 1000.0 kiloJoule asKiloWattHours -> 0.2778 kWh
