PhysicalValues/en
Notice: the physical values package as described here is still considered "work in progress" and provided as a preview feature. However it is quite stable and tested by an exhaustive test suite). We hope to have transcribed nature constant values and unit conversion factors correctly from public information (mostly wikipedia). Please report any errors or inconveniences (or wishes) to exept.
Inhaltsverzeichnis
- 1 Introduction & Motivation
- 2 No Warranty
- 3 Motivating Examples
- 3.1 Example1: Metric vs. Imperial Units
- 3.2 Example2: Time to Load a Cap (i.e. RC time constant)
- 3.3 Example3: Signal Rise Time
- 3.4 Example4: Bandpass Filter Frequency
- 3.5 Example5: Capacitance of a Wire
- 3.6 Example6: E = mcˆ2
- 3.7 Example7: Gravitational Force
- 3.8 Example8: British Drinking vs. US Drinking
- 3.9 Example9: Potential Energy
- 3.10 Example10: Voltage at a Loudspeaker
- 3.11 Example11: Energy of a Photon
- 4 Physic Package Loading
- 5 Programming Language API
- 6 Units
- 7 Unit API
- 7.1 Units vs. Values
- 7.2 SI Base and Derived Units
- 7.3 Printing Unit Values
- 7.4 Printing with another Unitstring
- 7.5 Converting Units
- 7.6 Predefined Converting Units
- 7.7 Predefined Scaling Units
- 7.8 Predefined Wellknown Units
- 7.8.1 Acceleration Unit
- 7.8.2 AmountOfSubstance Unit
- 7.8.3 Angle Unit
- 7.8.4 Area Unit
- 7.8.5 Bits & Bytes Units
- 7.8.6 Electric Charge Unit
- 7.8.7 Electric Current Unit
- 7.8.8 Electric Resistance Unit
- 7.8.9 Energy Unit
- 7.8.10 Force Unit
- 7.8.11 Frequency Unit
- 7.8.12 Length Unit
- 7.8.13 Mass Unit
- 7.8.14 Power Unit
- 7.8.15 Pressure Unit
- 7.8.16 Temperature Unit
- 7.8.17 Time Unit
- 7.8.18 Velocity Unit
- 7.8.19 Voltage Unit
- 7.8.20 Volume Unit
- 8 Per Unit Detailed API
- 8.1 Mass
- 8.2 Length
- 8.3 Angle
- 8.4 Temperature
- 8.5 Frequency
- 8.6 Energy
- 8.7 Power
- 8.8 Force
- 8.9 Area
- 8.10 Volume
- 8.11 Velocity (Speed)
- 8.12 Acceleration
- 8.13 Pressure
- 8.14 Voltage
- 8.15 Electric Current
- 8.16 Electric Resistance
- 8.17 Electric Capacitance
- 8.18 Electric Charge
- 8.19 Inductance
- 8.20 LuminousIntensity
- 8.21 Luminance
- 8.22 MagneticFlux
- 8.23 MagneticFluxDensity
- 8.24 CurrentDensity
- 8.25 Viscosity
- 8.26 Electric Conductance
- 8.27 Mass Density
- 9 English Engineering and Imperial Units (EEU)
- 10 Defining Additional Unit Converters
- 11 Instance Creation via Number Operators
- 12 Arithmetic
- 13 Formula Evaluation
- 14 Equation Solving
- 15 Providing additional Formulas
- 16 Nature Constants
- 17 Measured Physical Values
- 18 Physical Values and Numeric Precision
- 19 Printing Physical Values
- 20 Physical Values in Activity Diagrams
- 21 Physical Values as Freeze Value
- 22 Physical Values in Elementary Code
- 23 Math Language Workspace
- 24 Examples
- 24.1 Length Examples:
- 24.2 Velocity Examples
- 24.3 Mass Examples:
- 24.4 Temperature Examples:
- 24.5 Energy Examples:
- 24.6 Power Examples:
- 24.7 Electricity Examples:
- 24.8 Volume Examples:
- 24.9 Angle Examples:
- 24.10 Force Examples:
- 24.11 Pressure Examples:
- 24.12 Bytes Examples:
- 24.13 Misc Other Examples:
- 24.14 Other (Fun) Examples:
- 25 References
Introduction & Motivation[Bearbeiten]
In the past, a number of big projects failed or went completely out of budget due to misinterpretations of data. An example well known to insiders (but not named here) lead to millions of loss due to some misinterpretation of metric versus imperial values in documentation and software. In addition, some units are even different in imperial vs. american systems.
Expecco supports values with units, to represent physical values such as length, acceleration, area, volume, mass, temperature, electric current etc.
Physical values are useful for a nicer presentation of measurement values (e.g. in a report) and to convert between unit systems (e.g. metric vs. imperial vs. US). They can also make elementary code which computes physical values more readable and more robust. And if the correct unit is returned from an expression, you know that you used the correct formula (or at least: not completely wrong).
Physical values are implemented by the underlying Smalltalk system and can be used both in Smalltalk and in JavaScript elementary blocks. Similar public domain packages might be available for Java or Node. There is at least on such package available for Python (see "astropy"). These can be installed with "npm" or "pip".
However, there are currently no plans to transparently support exchange of physical values between expecco and Node, Java or Python. There is some support for Python's astropy quantities. If required, these should be passed as composite "{ unitAmount:xxx unit:xxx }
" or objects and converted in the bridge as required. Sorry, but there exists as yet no commonly used encoding standard for such data (e.g. in JSON).
The following document describes the programmer's API for elementary Smalltalk and JavaScript actions. Corresponding types are found in datatype menus under the "Physics" group.
This document is meant for "experts" who understand some minimum Smalltalk syntax (which is easy). It will help to write your own eleemntary code in case you need additional functionality.
No Warranty[Bearbeiten]
The nature constants and conversion factors have been taken from wikipedia and other sources.
We do not guarantee for their correctness. For some, new measures might give different values. If you encounter any errors or know about newer/better values, please let us know.
We recommend that you add additional verification/check actions (which should run before). A typical example wcould be:
self ssert:(1 pound printString = '453.59237 g').
That code will also document any of your expectations.
Motivating Examples[Bearbeiten]
The nice thing about using values with units is that you will get a better feedback if the used formula is correct (at least from the units point of view - forgotten scalar constants in physical expressions are still undetected). If you get an unexpected or strange unit in your result, you will certainly have an error in your computation.
Take these as examples and don't take the values for granted: please let us know, if there are any errors in those examples (the author is not an electrical engineer ;-).
Example1: Metric vs. Imperial Units[Bearbeiten]
Need to convert millimeters to inches, or know how thick a 3 AWG wire is?
Simply evaluate ("doIt") in a notepad or smalltalk elementary action's codeview:
10 milliMeter asInches => 0.393700787401575 in
or
(Physic::Length awgDiameter unitAmount:3) asMilliMeter => 5.82733981304513 mm
or:
(1 british gallon) asMilliLiter => 3785.411784 ml (1 american gallon) asMilliLiter => 4546.09 ml
Example2: Time to Load a Cap (i.e. RC time constant)[Bearbeiten]
You want to compute how long it takes to load a 100uF capacitor, given a 5V supply and a current limiting resistor with 100 kOhm?
First, compute the RC time constant; the electric charge (in Coulomb) transported through a wire is:
charge = I*t (I = current in Ampere; t in Seconds)
and the charge (in Coulomb) of a capacitor is:
charge = C*U (C = capacity in Farad; U = voltage)
We can immediately compute the electrical charge (in Coulomb) with the formula (C*U):
(5 volt * 100 micro farad)
and get the result:
(1/2000) C
Notice that the above is Smalltalk syntax, and can be written exactly like that in a Smalltalk action.
We can also compute the current through the loading resistor (I = U / R) as:
5 volt / 100 kilo ohm
and get the result:
50 µA
To compute the time, equate and rearrange the above formulas:
(C * U) t = ------- I
with I = U / R, we get:
(C * U) t = ------- (U / R)
in Smalltalk (*):
t := (5 volt * 100 micro farad ) / (5 volt / 100 kilo ohm)
and will get the RC time for t as:
10s
In other words, Smalltalk automatically found the correct result unit from the above computation and figured, that the result must be a time duration given in seconds.
(*) obviously, we could have further simplified the formula, or ask expecco to simplify it for us with:
Physic::Expression simplify:'(U * C) / (U / R)'
- or:
'(U * C) / (U / R)' asPhysicExpression simplified
- which both give the result:
C * R
- So, we could have also computed:
t := 100 micro farad * 100 kilo ohm
- and also get the same 10 seconds as result.
The capacitor's voltage will grow along a logarithmic curve, and is not fully charged after its RC time constant. Typical approximations will go for a 90% load, taking 3-5 times the RC time constant. (see wikipedia)
Example3: Signal Rise Time[Bearbeiten]
Of course, you may also get the time with a given delta-voltage and current flow. From the formula:
I = C * ΔV / Δt.
we get:
Δt = C * ΔV / I
As an example, if an output pin of an IC drives 10mA, and it is connected to an input pin with 100pF input capacitance to ground, it will take:
100 pico farad * 5 volt / 10 milli ampere
to get it from 0V to 5V (in this case: 50ns).
Example4: Bandpass Filter Frequency[Bearbeiten]
A filter's frequency is computed as:
1 f = ------------ 2*π*R*C
What is the frequency, given 1 Megaohm and 0.1 Microfarad as values?
In Smalltalk:
|r c f| r := 1 mega ohm. c := 0.1 micro farad. f := 1 / (2*Float pi * r * c)
result:
f = 1.59154943091895 Hz
Example5: Capacitance of a Wire[Bearbeiten]
Assume that there is a 10 cm long connection between 2 pins on a printed circuit board, and the connection faces a ground plane at a distance of 0.7 mm. The trace has a width of 0.5 mm.
What is the capacitance of the wire, and how long does it take the output to rise from 0 to 5 V if it can drive 10 mA?.
The capacitance is:
C = ε0 * a / d
where ε0 is the permittability constant, a is the area and d is the distance of the capacitor's plates. We take the vacuum permutability as an approximation (strictly speaking, that is incorrect; it should be replaced by the printed board material's value and also depends on the frequency [1]). The trace has an area of 10 cm by 0.5 mm, and has a distance of 0.7mm from the ground plate. Thus we get:
a := 10 centi meter * 0.5 milli meter. "area" d := 0.7 milli meter. "distance" e0 := Physic::NatureConstants vacuumPermittivity. "ε0" C := e0 * a / d.
or:
C := Physic::NatureConstants vacuumPermittivity "ε0" * (10 centi meter * 0.5 milli meter) / 0.7 milli meter.
that gives us 0.63 pF. According to the above Example2, we can compute the signal's rise time as:
0.63 pico farad * 5 volt / 10 milli ampere
which gives: 315 ps
or as a frequency:
1 / 315.0 pico seconds => 3174.60317460317 Mhz
Example6: E = mcˆ2[Bearbeiten]
Energy content of 1 gram of mass:
c := Physic::NatureConstants lightspeed. 1.0 gram * c squared => 89.8755178736818 TJ
c := Physic::NatureConstants lightspeed. (1.0 gram * c squared) asKiloWattHours => 24965421.6315783 kWh
c := Physic::NatureConstants lightspeed. (1.0 gram * (c ** 2)) asMegaWattHours rounded => 24965 MWh
We'd love to use antimatter for energy supply!
Example7: Gravitational Force[Bearbeiten]
F = (m1 * m2) * G / rˆ2
Force on two masses separated by one meter:
m1 := 1 kiloGram. m2 := 1 kiloGram. G := Physic::NatureConstants gravitationalConstant. r := 1 meter. (m1 * m2 * G) / r squared => 6.6743e-11 N
or (in one expression):
(1 kiloGram * 1 kiloGram * (Physic::NatureConstants gravitationalConstant)) / 1 meter squared => 6.6743e-11 N
Example8: British Drinking vs. US Drinking[Bearbeiten]
Who gets most bang for the glas in a pub: British, US or German drinkers?
1 british pint => 568.26125 ml 1 american pint => 473.176473 ml (1/2) liter => 500 ml
Example9: Potential Energy[Bearbeiten]
The potential energy of 10 gram lifted 1 meter (m*h*G) is on earth:
10 gram * 1 meter * (Physic::NatureConstants earthGravity) => 0.0980665 J
or alternatively:
10 gram * 1 meter * (Physic::NatureConstants astronomicalObjects['earth']['gravity']) => 0.0980665 J
or even:
10 gram * 1 meter * (Physic::NatureConstants earth gravity) => 0.0980665 J
Example10: Voltage at a Loudspeaker[Bearbeiten]
Lets assume, we want to get 20 Watt out of a 4 Ohm loudspeaker. Which voltage will we need (only assuming non-complex resistance).
The formulas are:
P = U * I (power is voltage times current) and U = R * I (voltage drop is resistance times current).
Lets rewrite into
U = P / I and I = U / R.
Then replace I in the first formula to get
U = P / (U/R) or U = P * R) / U
Multiply both sides by U, we get:
U^2 = P * R or U = SQRT( P * R)
Lets evaluate:
(20 watt * 4 ohm) => 8.9443 V
(you'll need an up-to-date version of expecco for this, as previous versions did not recognize square roots of formulas correctly, delivering a funny unit as result).
Example11: Energy of a Photon[Bearbeiten]
The frequency f of a photon with a wavelength of 550 nanometer is:
f := Physic::NatureConstants c / 550 nano meter => 545.077 THz
and its energy is the Planck constant h times the frequency:
e := Physic::NatureConstants h * f => 3.61171974027078e-19 J
in electron volts gives:
e asElectronVolts => 2.25425815333091 eV
Physic Package Loading[Bearbeiten]
If you have an older expecco version, the physic packages (stx:goodies/physic/units
for units and stx:goodies/physic/formula
for formula parsing) may not be already loaded.
If not, either add it to the list of required packages of your test suite or evaluate:
Smalltalk requirePackage:'stx:goodies/physics/units'. Smalltalk requirePackage:'stx:goodies/physics/formula'.
in either an elementary action or in the startup file ("expeccoStart.rc
").
All physic classes will be found in the "Physic
" namespace
(i.e. class names are prefixed with "Physic::
" as in "Physic::Energy
" or "Physic::Volume
").
Programming Language API[Bearbeiten]
Smalltalk
As you'll have noticed, Smalltalk has a convenient syntax, for this kind of framework: you can immediately write code like:
1 kilo meter / 10 minutes
to compute a velocity.
JavaScript
Due to the fact that the builtin Javascript also allows for numbers to be treated like objects, the same code written in JavaScript still looks somewhat readable:
1.kilo().meter() / 10.minutes()
although the parentheses make the code somewhat ugly.
All code fragments in the following document are written in Smalltalk syntax (add periods and parentheses to get the corresponding JS code).
Units[Bearbeiten]
Base Units[Bearbeiten]
All base units are measured in their corresponding SI standard units and print with an appropriate scaling prefix. I.e. by default, the unit chooses a "reasonable" 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 (e.g. if you insist on printing a mass in pounds, in grams, etc.) or if you want to enforce a particular scaling SI prefix (e.g. to enforce printing output in "cm" instead of "m" or "mm").
See examples below on how those converters affect the printout of a value.
Independent from any enforced print format, the internal representation of physical values is always using base unit amounts (i.e. SI units).
Base units are:
Unit Name Smalltalk Description ----------------------------------------------- s Second second time m Metre metre or meter length kg Kilogram kilogram mass A Ampere ampere electric current K Kelvin kelvin temperature mol Mole mole amount of substance cd Candela candela luminous intensity
To get a constant physical value in your Smalltalk code, write a number followed by the unit name (in lowercase). For example:
1 second => 1s 1 meter => 1 m 1 kilogram => 1 kg 1 ampere => 1 A 1 kelvin => 1 K 1 mole => 1 mol 1 candela => 1 cd
(in other words: there are a number of methods defined in the Number class, which take the receiver and construct a corresponding unit instance from it. These methods are named after the SI unit names).
Derived Units[Bearbeiten]
Additional derived units are:
Unit Name Smalltalk Description ------------------------------------------------------------- V Volt volt voltage Hz Hertz hertz frequency m/s Meter per Second meterPerSecond speed, velocity m/s² m/s per Second meterPerSecondPerSecond acceleration m² Square Meter squareMeter area m³ Cubic Meter cubicMeter volume pa Pascal pascal pressure W Watt watt power N Newton newton force J Joule joule energy Ω Ohm ohm electric resistance S Siemens siemens electric conductance C Coulomb coulomb electric charge F Farad farad electric capacitance H Henry henry electric inductance T Tesla tesla magnetic flux density rad Radian radian angle sr Steradian steradian solid angle ° Degrees degrees angle
Plus possibly more, by the time you read this.
There are a number of less frequently used derived units, for which no Smalltalk shortcut exists.
These might result from computations with physical values or be instantiated by sending explicit constructor messages to the unit (instead of sending a message to a number).
These are described below.
Converting Units[Bearbeiten]
By default, values are presented as SI units. However, you may want to convert the to other unit systems. For this, converting units are provided. These present a value in another unit system. For example as a value in imperial units (Inches, Pounds, etc.). Like all physical values they keep the actual amount internally in multiples of the SI base unit (metric), but will show the value with some scaling and with another unitString (eg. 'lb' or 'ft').
You can ask any other unit (usually a base unit) for a converting unit via getter messages, or by asking for a unit by its formula or by name.
For example, you can ask the Length base unit for a number of common converting units:
Physic::Length yards => a unit which presents its metric amount in yards Physic::Length inches or inches Physic::Length feetAndInches ...he's 5 foot 2, he's 6 foot 4... Physic::Length angstrom => a unit which presents its amount in angstrom Physic::Length lightYears or light years Physic::Length awgDiameter => presents its amount as american wire gauge diameter
and then create a value for it with the "unitAmount:
" message.
This will generate a value in multiples of the message-receiver's unit, as in:
Physic::Length yards unitAmount:5 => 5 yd
The list of converting units available per unit is shown below.
Scaling Units[Bearbeiten]
As already mentioned above, unit values by default determine themself how small or large amounts are printed. For example, the Length unit will print amounts with an SI scale (kilo, mega, milli, etc.). Thus, when the value "4.5 milli meter" is printed (or displayed), it will present itself as "4.5 mm" (not as "0.45 cm" or "0.0045 m"). The scale used depends on heuristic and is chosen to conform to usual human written conventions.
You can convert any physical value to one where this heuristic is overwritten and an explicit SI-scale is preferred. For this, use a Scaling Unit. Specifying an explicit scaling unit is useful if you want to present values in a table or if you have to export values in a particular scale to some other program. Notice that the value of the scaling unit instance is still same - the only difference is how it prints itself.
Scaling units will print the amount with an explicit scale. Any unit can be asked for a scaling unit, although not all combinations are typically used in real live: for example, no-one would write "2 Hm" (hecto meter) or "1 Mm" (mega meter).
You can get a scaling unit from any other unit with one of:
nanoUnit, microUnit, milliUnit, centiUnit, deciUnit, hectorUnit, kiloUnit, megaUnit, gigaUnit, etc.
(any of the possible scaling prefixes listed below concatenated with "Unit")
Similar to the above, you can create values with "unitAmount:
", as in:
Physic::Mass pounds kiloUnit unitAmount:2
to create a mass of "2 kilo pounds (imperial)" which prints itself as "2 klb".
Or:
Physic::Frequency kiloUnit unitAmount:10
to enforce that the frequency will be printed in kilohertz.
There is also a special "unitUnit
", which prints its values as SI base units (without any scaling prefix). Use this eg. to enforce a length value to always print itself as meters.
Conversion methods are also available on values. Every physical value can be converted using one of the messages:
asKiloUnitValue, asMilliUnitValue, asMicroUnitValue, etc.
And you get a base unit value using "asUnitUnitValue
".
Thus, "4.5 milli meter asCentiUnitValue
" will present itself as "0.45 cm"
and "4.5 milli meter asUnitUnitValue
" as "0.0045 m".
Unit vs. BaseUnit[Bearbeiten]
As described, there are base units (eg. Meter, Kilogram, etc.) and their combinations (eg. Acceleration, Velocity, Energy ec.) and converting units such as Imperial Pound, Feet, Nautical Mile etc.
Every unit understands two pairs of value generator and value extracting messages:
unitAmount: / unitAmount
and:
baseUnitAmount: /baseUnitAmount
the unitAmount is the amount in that value's converted amount (eg. in Feet or Acre), whereas the baseUnitAmount is always the amount in the SI base or combination unit (eg. in Meter or SquareMeter).
Thus, every length unit will return a length of 1 meter if created with the "baseUnitAmount:" instance creation message; independent on how it will later be printed.
And every length unit will return a length with its own scale value via the "unitAmount:" creation message. For base units and immediate derived units, the baseUnit amount it the same as the unit amount.
For example:
(Physic::Length unitAmount:2) => 2 m (Physic::Length baseUnitAmount:2) => 2 m (Physic::Length feet unitAmount:2) => 2 ft (Physic::Length feet baseUnitAmount:2) => 6.56167979002624 ft (because 2 meters - the base unit value - is 6.56 ft)
(Physic::Length unitAmount:2) unitAmount => 2 (Physic::Length baseUnitAmount:2) unitAmount => 2 (Physic::Length unitAmount:2) baseUnitAmount => 2 (Physic::Length baseUnitAmount:2) baseUnitAmount => 2
(Physic::Length feet unitAmount:2) unitAmount => 2 (Physic::Length feet baseUnitAmount:2) unitAmount => 6.56167979002624 (Physic::Length feet unitAmount:2) baseUnitAmount => 0.6096 (Physic::Length feet baseUnitAmount:2) baseUnitAmount => 2
(Physic::Length unitAmount:10000000) unitAmount => 10000000 (Physic::Length meter unitAmount:10000000) unitAmount => 10000000 (Physic::Length meter unitAmount:10000000) baseUnitAmount => 10000000
but when printed:
(Physic::Length unitAmount:10000000) printString => 10000 km (Physic::Length meter unitAmount:10000000) printString => 10000000 m
In addition, physical value instances can be converted to their corresponding SI base unit value via "asBaseUnitValue". ANd of course, values in base units will return themself.
For example:
(Physic::Length unitAmount:2) asBaseUnitValue => 2 m (Physic::Length feet unitAmount:2) asBaseUnitValue => 0.6096 m (Physic::Length meter unitAmount:10000000) asBaseUnitValue => 10000 km
More on this below in the physical values chapter.
Number Prefix Messages[Bearbeiten]
SI Prefix[Bearbeiten]
Numbers (in Smalltalk and JavaScript) can be scaled by an SI prefix message.
Thus, when combining a unit message with a scaled number, we get a scaled physical value.
For example, without SI prefix, we get:
1 gram => '1 g'
whereas with a 'micro' prefix, the result is:
1 micro gram => '1 µg'
or:
1 hecto liter => '100 liter'
The corresponding JavaScript code is similar, but slightly less elegant looking due to the required periods and parentheses:
1.gram() 1.micro().gram() 1.hecto().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 ronna 1E+27 1000000000000000000000000000 quetta 1E+30 1000000000000000000000000000000
You can combine the SI scale with a unit, as in:
1 kilo meter 1 micro ampere 1 mega watt 1 pico farad 1 exa bytes
For some common units, additional shortcuts exist:
1 kiloMeter ; centiMeter ; milliMeter ; microMeter ; nanoMeter 1 milliGram ; microGram 1 kiloAmpere ; milliAmpere ; microAmpere ; nanoAmpere 1 kiloVolt ; milliVolt ; microVolt 1 kiloByte ; megaByte ; teraByte ; peraByte ; exaByte 1 kiloJoule ; megaJoule 1 kiloHertz ; megaHertz ; gigaHertz 1 kiloOhm ; megaOhm 1 kiloWatt ; teraWatt ; gigaWatt ; megaWatt ; milliWatt
But in general, you will have to combine the SI scale with a unit as described above.
Bits & Bytes[Bearbeiten]
In addition to the above listed powers-of-10 scaling prefixes, there are also powers-of-2 prefixes, which are usually only used with byte or bit amounts.
kibi 2ˆ10 1024 mebi 2ˆ20 1048576 (same as "1024 * 1024" or "1024 kibi") gibi 2ˆ30 1073741824 (same as "1024 * 1024 * 1024" or "1024 mebi) tebi 2ˆ40 1099511627776 pebi 2ˆ50 1125899906842624 exbi 2ˆ60 1152921504606846976 zebi 2ˆ70 1180591620717411303424 yobi 2ˆ80 1208925819614629174706176
For the kibi scaler, you can use the shortcut:
1 kibiByte => 1024 B
all others need to be combined, as in:
1.0 mebi byte => 1024 kiB 1.0 mebi byte asMegaBytes => 1.048576 MB 1.0 mebi byte asMebiBytes => 1 MiB 1.0 mebi bits => 1048.576 kbit 1.0 mebi bits asMegaBytes => 0.131072 MB 1.0 mebi bits asMebiBytes => 0.125 MiB
Hundreds, thousands etc.[Bearbeiten]
In addition, the prefixes "hundred", "thousand" and "million" are supported:
1 hundred million kilo gram =>100000000 kg
To represent the pressure inside the sun, write:
26.5 million giga pascal => 2.65e+16 Pa
or
26.5 million giga pascal asPSI => 3843364757070.34 psi
There is intentionally NO SUPPORT for billion, trillion etc., because most german journalists and even some non journalists have no idea about US vs. continental meanings of those (big smiley here). In britain, its even worse, where both systems are used in parallel (https://de.wikipedia.org/wiki/Billion).
Imperial / American / Metric Prefix[Bearbeiten]
For some units, additional prefixes are allowed.
american / imperial:
barrel, cup, floz, gallon, pint, quart, tablespoon, teaspoon dry pint, dry quart, dry peck
metric / imperial:
ton, hp
I.e. you can write:
1 imperial gallon => 4.54609 l 1 american gallon => 3.785411784 l 1 metric ton => 1000 kg 1 imperial ton => 1016.0469088 kg 1 imperial teaspoon => 5.91939880031792 ml 1 american pint => 473.176473 ml 1 american dry pint => 550.6104713575 ml
Square / Cubic Prefix[Bearbeiten]
For readability, there are also a square and cubic prefíxes, usable with: centiMeter. feet, inches, kiloMeter, meter, miles, milliMeter, yards.
You can write:
1 square meter => 1 m² 1 cubic feet => 28.316846592 l 1 square yard => 0.83612736 m²
Troy Prefix[Bearbeiten]
For readability, there is also a troy prefíx, usable only with ounces.
You can write:
1 troy ounce => 31.1034768 g 1 american ounce => 28.349523125 g 1 british ounce => 28.349523125 g
Unit API[Bearbeiten]
Units vs. Values[Bearbeiten]
Internally, PhysicalValues are represented as a pair of a PhysicalUnit and an amount. PhysicalUnit may be either one of the above listed base units (i.e. SI base units), or a scaling/converting unit (e.g. Inches or Hectare but also MilliMeter). The amount is always the baseUnit amount i.e. meter, kilogram, square meter etc.
Units[Bearbeiten]
You can get a unit (in contrast to a value) by sending one of the unit-messages to the Physic::PhysicalUnit class (i.e. the class named "PhysicalUnit" in the "Physic" namespace).
For example,
Physic::PhysicalUnit energy
will give you the "Energy" class which represents values in "Joule".
Conversion units are retrieved by asking one such unit for another unit, by sending it a corresponding getter message.
For example, we can ask the Energy class for a converting class named "Calories" or "KiloCalories" with:
Physic::PhysicalUnit energy calories Physic::PhysicalUnit energy kilo calories
Actually, you can also ask the (abstract) PhysicalUnit class for a unit:
Physic::PhysicalUnit calories Physic::PhysicalUnit kilo calories
Values[Bearbeiten]
On the basic level, PhysicalValue are created by sending the "unitAmount:
" or "baseUnitAmount:
message to a unit. However, for the most common units, convenient and more readable messages are implemented in the Number hierarchy. These allow for shorter code and will be described below.
For example:
Physic::PhysicalUnit energy unitAmount:100 => 100 J
generates an energy instance of 100 joule.
The argument of the "unitAmount:
" call is always given in units of the receiver unit, whereas the alternative constructor named "baseUnitAmount:
" expects the argument to be in the underlying base unit (i.e. one of the SI units).
This makes no difference for the base SI units, but is relevant, if you deal with conversion units (e.g. imperial units) as described later.
Thus,
Physic::PhysicalUnit energy calories unitAmount:100 => 100 cal Physic::PhysicalUnit calories unitAmount:100 => 100 cal
will create an energy instances of 100 calories (which will print themself as 100 calories),
whereas:
Physic::PhysicalUnit energy calories baseUnitAmount:100 => 23.9005736137667 cal
will create an energy instance of 100 joule (but it will print itself as 23.90 calories).
Notice, that the "energy
" message is a facade getter method of Physic::PhysicalUnit. It retrieves the Energy class, which is actually named "Physic::Energy" and is also located in the Physic namespace.
So we could have written:
Physic::Energy calories unitAmount:100 => 100 cal
or, given 100 joule:
Physic::Energy calories baseUnitAmount:100 => 23.9005736137667 cal
Value Creation[Bearbeiten]
Given one of the units as listed below, a value instance can be created by different ways:
Given an amount in that unit, as in:
Physic::Mass kilogram unitAmount:1.5. => 1.5 kg Physic::Mass troyOunces unitAmount:1.5. => 1.5 oz t
Given an amount in base SI units (same as unitAmount for the SI units, but different for derived units):
Physic::Mass kilogram baseUnitAmount:1.5. => 1.5 kg Physic::Mass troyOunces baseUnitAmount:1.5. => 48.226119852942 oz t. (i.e. 1.5kg as troy ounces)
By converting, given a value in any unit and a target unit:
(Physic::Mass kilogram unitAmount:0.1) as:(Physic::Mass troyOunces) => 3.2150746568628 oz t. (i.e. 0.1 kg as troy ounces)
same, but given a target unit's name:
(Physic::Mass kilogram unitAmount:0.1) as:'Pounds' => 0.220462262184878 lb.
or given a target unit's unitString:
(Physic::Mass kilogram unitAmount:0.1) as:'lb' => 0.220462262184878 lb.
SI Base and Derived Units[Bearbeiten]
Getters for well known units are:
Physic::PhysicalUnit acceleration Physic::PhysicalUnit amountOfSubstance Physic::PhysicalUnit angle Physic::PhysicalUnit area Physic::PhysicalUnit currentDensity Physic::PhysicalUnit electricCapacitance Physic::PhysicalUnit electricCharge Physic::PhysicalUnit electricConductance Physic::PhysicalUnit electricCurrent Physic::PhysicalUnit electricResistance Physic::PhysicalUnit energy Physic::PhysicalUnit force Physic::PhysicalUnit frequency Physic::PhysicalUnit inductance Physic::PhysicalUnit length Physic::PhysicalUnit luminousIntensity Physic::PhysicalUnit mass Physic::PhysicalUnit massDensity Physic::PhysicalUnit power Physic::PhysicalUnit pressure Physic::PhysicalUnit specificVolume Physic::PhysicalUnit temperature Physic::PhysicalUnit time Physic::PhysicalUnit velocity Physic::PhysicalUnit voltage Physic::PhysicalUnit volume Physic::PhysicalUnit knownUnits
The last returns a collection of all known units (there are actually more than listed above).
The very most used units are directly accessible via a global under the Physic namespace:
Physic::Mass Physic::Length Physic::Energy Physic::Velocity etc.
For common units, additional instance creation protocol is provided in the Number class. E.g.:
100 joule
=> 100 J
will generate the same as:
(Physic::PhysicalUnit energy) baseUnitAmount:100
=> 100 J
which is the same as:
Physic::Energy baseUnitAmount:100
=> 100 J
which (for base units) is the same as:
Physic::Energy unitAmount:100
=> 100 J
The additional Number-protocol is described below.
In the above examples, the unit was a baseUnit, and therefore the baseUnitAmoun the same as the unitAmount.
Things are different for derived units:
Physic::Energy calories unitAmount:100
=> 100 cal
vs.
Physic::Energy calories baseUnitAmount:100
=> 23.9005736137667 cal (because these are 100 joule)
More on that below.
Printing Unit Values[Bearbeiten]
When printed, physical values will scale and use an SI prefix as appropriate.
For example, by default, a value of 10 millimeter will print as "10 mm" instead of "0.01 m" (remember: meter is the underlying SI base unit). The choice of prefix (milli, micro, nano, etc.) is decided by the unit's "printWithUnit:on:" method, which in case of length values chooses an appropriate prefix from nanos to lightyears, based on heuristics.
This print behavior can be changed by converting to an explicit converting unit via one of the "asXXX
" messages listed below. However, the SI base unit amount will be kept internally and used in arithmetic operations. Thus, e.g. when adding a meter with inches, an SI meter value will be generated, and the result will be presented in the same unit as the receiver (first operand).
For example:
1 inch
returns an SI base-unit value (i.e. in meters) and will print as meter (actually as '25.4 mm'), whereas:
1 inch asInches
will print itself as inches because of the "asInches" message.
All of:
1 meter + 1 inch 1 meter + 1 inch asInches 1 inch + 1 meter
will print as meter ('1.0254 m'), because the first operand's unit determines the unitString.
However,
1 inch asInches + 1 meter 1 inch asInches + 1 meter asInches
will all print as inches ('40.37 in').
You can also pass a target unit string, as in:
1 meter as:'in'
or the target unit:
1 meter as:(Physic::Length inches)
or the unit's name:
1 meter as:'Inches'
which all print as '39.3700787401575 in'.
Printing with another Unitstring[Bearbeiten]
Some units are printed with different unit symbols, depending on context.
For example, nautical miles are printed in aviation as "NM", whereas in US official documents they are printed as "nmi". And a german document might want to print them as "sm" ("Seemeilen").
For that, convert the value (or unit) with "withUnitSymbol:
".
For example, a value of two nauticalMiles is printed in different units:
2 nauticalMiles printString => '3704 m' 2 nauticalMiles asNauticalMiles printString => '2 NM' (2 nauticalMiles asNauticalMiles withUnitSymbol:'nmi') printString => '2 nmi' (2 nauticalMiles asNauticalMiles withUnitSymbol:'sm') printString => '2 sm'
Applying the above message to a unit (instead of a value) gives a new unit.
For example, a bottle unit, which corresponds to 0.7 lters:
bottleUnit := Physic::Volume liter withUnitSymbol:'bottle' scaleFactor:0.7.
can create bottle-values:
(bottleUnit unitAmount:10) => 10 bottle
or convert from liters:
10 liter as:bottleUnit => 14.286 bottle
Printing in Another Language[Bearbeiten]
The same scheme can be used to print values with national translations of a unit.
For example, tons of coal equivalents ('toe') is "Tonnen Steinkohle Äquivalent" or tSKE in German.
Reasonable definitions could be:
toeGerman := Physic::Energy toe withUnitSymbol:'tSKE' scaleFactor:1. mtoeGerman := toeGerman megaUnit.
so the mtoeGerman unit will represent megatons of coal equivalents and print its values with a 'MtSKE' unit (see scaling units below):
mtoeGerman unitAmount:100 => 100 MtSKE
and
(mtoeGerman unitAmount:100) asGigaJoules => 4186800000 GJ
or:
(mtoeGerman unitAmount:100) as:'PJ' => 4186.8 PJ
Similar:
meterChinese := Physic::Length withUnitSymbol:'米 (Mǐ)' scaleFactor:1. meterChinese unitAmount:15 => 15 米 (Mǐ)
Converting Units[Bearbeiten]
In addition to predefined converting units, as listed below, it is also possible to define custom units, with different (customizable) print behavior (more on that below).
Predefined Converting Units[Bearbeiten]
Some such custom units are already predefined; for example, to represent imperial units, conversion units derived from mass are found (among others) as:
Physic::PhysicalUnit mass ounces (or Physic::Mass ounces) Physic::PhysicalUnit mass pounds (or Physic::Mass pounds)
and length units as:
Physic::PhysicalUnit length inches (or Physic::Length inches) Physic::PhysicalUnit length feet Physic::PhysicalUnit length yards
Thus, you can create unit values which print themself (e.g.) in imperial units:
yardsUnit := Physic::Length yards. distance := yardsUnit unitAmount:10
will give you 10 yards, which prints itself as such ('10 yd').
Whereas:
distance2 := yardsUnit baseUnitAmount:10
will create a distance of 10 meters (the underlying base unit), which prints itself in yards.
Be careful to not confuse unit amounts with base unit amounts, and be reminded that the internal storage representation of all units is always in SI base units. The conversion is only performed when such values are printed.
In general, you can ask most base units for common conversion units (which are the units used by the asXXX converters below).
These can also be used to instantiate instances or for conversion.
E.g.
Physic::Mass ounces unitAmount:1
returns 1 ounce (which prints itself as such), and:
1 kiloGram as:(Physic::Mass ounces)
returns 32.27 ounces (which also prints itself as such).
Predefined Scaling Units[Bearbeiten]
By default, the unit chooses itself, how values are scaled when printing. For example, "(1/1000.0) kilo gram" will print itself as "1 g", although the underlying baseUnit is kilogram.
You can force a particular scale either by using one of the scale-converting units, eg:
someUnit asMilliUnit baseUnitAmount:scalarValueInBaseUnits
or by giving it a unit amount:
someUnit asMilliUnit unitAmount:scalarValueInUnits
or by converting a unit-value:
someUnitValue asMilliUnitValue
Again, scalarValueInBaseUnits is in base-units (kg, N, Hz,...), whereas scalarValueInUnits is in scaled-units (mg, kN, Mhz,...).
For example:
0.01 kilo gram => prints as "10 g" Physic::Mass baseUnitAmount:0.01 => prints as "10 g" Physic::Mass milliUnit baseUnitAmount:0.01 "/ specified in kg here => prints as "10000 mg" Physic::Mass milliUnit unitAmount:100 "/ specified in mg here => prints as "100 mg"
To get a scaling unit from a given base unit (such as "Mass", "Length", "Volume", etc.) or from a given derived Unit (such as "Volume liters"), apply one of the following:
aUnit picoUnit aUnit nanoUnit aUnit microUnit aUnit milliUnit aUnit centiUnit aUnit deciUnit aUnit hectoUnit aUnit kiloUnit aUnit megaUnit aUnit gigaUnit aUnit teraUnit aUnit petaUnit aUnit exaUnit
For example, if you have to work with hectoliters (units of 100 liters), which is common in europe's farming, make yourself a corresponding unit with:
hlUnit := Physic::Volume liters hectoUnit. wine := hlUnit unitAmount:15.0. wine printString => 15 hl" wine asCubicMeters printString => 1.5 m³" wine asLiters printString => 1500 l wine asGallonsUS printString => 396.258078537223 US gal (wine asGallonsUS roundTo:0.01) printString => 396.26 US gal
To convert a given value (as opposed to a unit as above), use one of:
aValue asPicoUnitValue aValue asNanoUnitValue aValue asMicroUnitValue aValue asMilliUnitValue aValue asCentiUnitValue aValue asDeciUnitValue aValue asHectoUnitValue aValue asKiloUnitValue aValue asMegaUnitValue aValue asGigaUnitValue aValue asTeraUnitValue aValue asPetaUnitValue aValue asExaUnitValue
therefore, to force a physical value to print itself in its 'milli' unit, use asMilliUnitValue, as in:
i := 1 ampere. m_i := i asMilliUnitValue.
The asXXXUnitValue methods work on any physical value,
However, you can also and should use the unit-specific converters, here:
m_i := i asMilliAmperes
or with masses, as in the above example:
0.01 kilo gram asMilliUnitValue 0.01 kilo gram asMilliGrams
The unit-specific methods will only work on their specific unit values (meaning that you get an error when trying to ask any non-mass value for its milligrams). Thus, the later are preferable, as they provide an additional quality check for your code. For a list of unit-specific converters, see below.
Predefined Wellknown Units[Bearbeiten]
The base SI units Mass, Length, Force, etc. can be directly accessed from the Physic namespace as Physic::<nameOfUnit>
.
Other derived and less frequently units can be accessed either via getters from the Physic::PhysicalUnit class, or by asking it via Physic::PhysicalUnit unitNamed:'nameOfUnit'
.
A list of known basic and derived SI units is retrieved with Physic::PhysicalUnit knownUnits
.
For details, see US Units, CGS System, Avoirdupois and SI Units.
Acceleration Unit[Bearbeiten]
- Physic::Acceleration
- The base unit is "m/s²".
- Physic::Acceleration gForce
- Returns the "GForce" converting unit (i.e. units o earth's gravitation).
AmountOfSubstance Unit[Bearbeiten]
- Physic::AmountOfSubstance
- The base unit is "mol".
- Physic::AmountOfSubstance particles
- Returns the (number of) "Particles" converting unit.
Angle Unit[Bearbeiten]
- Physic::Angle
- The base SI unit. Prints as "rad".
- Physic::Angle degrees
- Returns the "Degrees" converting unit. Prints its values in degrees.
- Physic::Angle degreeAndMinAndSec
- Returns a converting unit which prints its values in integer degrees plus minutes (1/60s degrees) plus seconds (1/3600s degrees).
- Physic::Angle gon
- Returns the "Gon" converting unit.
- Physic::Angle radians
- Returns the "Radians" converting unit.
- Physic::Angle arcMin
- Returns the "ArcMinutes" converting unit.
- Physic::Angle arcSec
- Returns the "ArcSeconds" converting unit.
- Physic::Angle arcMinAndSec
- Returns the "ArcMinutesAndSeconds" converting unit.
Area Unit[Bearbeiten]
- Physic::Area
- The base SI unit. Prints as square meters.
- Physic::Area acre
- converting unit which prints as acres.
- Physic::Area are
- Prints as ares.
- Physic::Area awg
- converting unit which prints as American Wire Gauge.
- Physic::Area hectare
- Prints as hectares (ha).
- Physic::Area squareFoot
- Prints as square feet (sq ft).
- Physic::Area squareMiles
- Prints as square miles (sq mi).
- Physic::Area squareMillimeterMeters
- Prints as square millimeters (mm2).
- Physic::Area squareCentiMeters
- Prints as square centimeters (cm2).
- Physic::Area squareMeters
- Prints as square meters (m2).
- Physic::Area squareKiloMeters
- Prints as square kilometers (km2).
Bits & Bytes Units[Bearbeiten]
- Physic::Bytes
- The bytes unit. Not really an SI unit, but useful for printing file sizes.
- Physic::Bytes kiloBytes
- a converting unit; prints as "kB".
- Physic::Bytes megaBytes / gigaBytes / teraBytes etc.
- converting units; print as "MB", "GB", "TB", etc.
- Physic::Bytes kibiBytes / mebiBytes / gibiBytes / tebiBytes etc.
- converting units; print as "kiB", "MiB", "GiB", "TiB", etc.
- Physic::Bits
- The bits unit. Not really an SI unit, but useful for printing transmission speeds (bits/s).
- Physic::Bits kiloBits
- a converting unit; prints as "kbit".
- Physic::Bits megaBits / gigaBits / teraBits etc.
- converting units; print as "Mbit", "Gbit", "Tbit", etc.
- Physic::Bits kibiBits / mebiBits / gibiBits / tebiBits etc.
- converting units; print as "kibit", "Mibit", "Gibit", "Tibit", etc.
Electric Charge Unit[Bearbeiten]
- Physic::ElectricCharge
- The base SI unit. Prints as coulomb ("C").
- Physic::ElectricCharge ampereSeconds
- a converting unit which prints as "As".
- Physic::ElectricCharge ampereHours
- a converting unit which prints as "Ah".
- Physic::ElectricCharge elementaryCharges
- a converting unit which prints as number of elementary charges "q".
Electric Current Unit[Bearbeiten]
- Physic::ElectricCurrent
- The base SI unit. Prints as ampere ("A").
Electric Resistance Unit[Bearbeiten]
- Physic::ElectricResistance
- The base SI unit. Prints as ohm.
Energy Unit[Bearbeiten]
- Physic::Energy
- The base SI unit. Prints as joules ("J").
- Physic::Energy wattHours
- a converting unit which prints as "Wh"
- Physic::Energy kiloWattHours
- a converting unit which prints as "kWh"
- Physic::Energy megaWattHours
- a converting unit which prints as "MWh"
- Physic::Energy gigaWattHours
- a converting unit which prints as "GWh"
- Physic::Energy kiloJoules
- a converting unit which prints as "kJ"; same as "Energy kiloUnit"
- Physic::Energy megaJoules
- a converting unit which prints as "MJ"; same as "Energy megaUnit"
- Physic::Energy gigaJoules
- a converting unit which prints as "GJ"; same as "Energy gigaUnit"
- Physic::Energy btu
- a converting unit which prints as "btu" (British Thermal Units), 1055 J based on the ISO 31-4 definition
- Physic::Energy boe
- a converting unit which prints as "boe" (Barrels of Oil Equivalent, 6117.9 MJ based on the US Internal Revenue Service)
- Physic::Energy toe
- a converting unit which prints as "toe" (Tons of Oil Equivalent), 41.9 GJ
- Physic::Energy tce
- a converting unit which prints as "tce" (Tons of Coal Equivalent), 29 GJ
- Physic::Energy calories
- a converting unit which prints as "cal"
- Physic::Energy kiloCalories
- a converting unit which prints as "kcal"
- Physic::Energy electronVolts
- a converting unit which prints as "eV"
- Physic::Energy kiloElectronVolts; same as "Energy electronVolts kiloUnit".
- a converting unit which prints as "keV"
- Physic::Energy erg
- a converting unit which prints as "erg"
Force Unit[Bearbeiten]
- Physic::Force
- The base SI unit. Prints as Newton.
- converting units are returned by: dyne, gramForce, newtons, poundForce, tonForce
Frequency Unit[Bearbeiten]
- Physic::Frequency
- The base SI unit. Prints as Hertz.
- converting units are returned by: hertz, kiloHertz, megaHetz, gigaHertz, rpm.
Length Unit[Bearbeiten]
- Physic::Length
- The base SI unit. Prints as Meter with a reasonable scale prefix.
- Physic::Length centiMeters
- a converting unit which prints as "cm".
- Physic::Length milliMeters
- a converting unit which prints as "mm".
- Physic::Length microMeters
- a converting unit which prints as "µm".
- Physic::Length nanoMeters
- a converting unit which prints as "nm".
- Physic::Length meters
- a converting unit which always prints as "m".
- Physic::Length kiloMeters
- a converting unit which prints as "km".
- Physic::Length inches
- a converting unit which prints as "in".
- Physic::Length feet
- a converting unit which prints as "ft".
- Physic::Length feetAndInches
- a converting unit which prints feet and inches.
- Physic::Length feetAndInchesRounded
- a converting unit which prints feet and rounded inches; a typical format used in the US for a human's height
- Physic::Length metersAndCentimeters
- a converting unit which prints meter and rounded centimeters; a useful format a human's metric height
- Physic::Length yards
- a converting unit which prints as "yd".
- additional converting units are returned by: angstrom, astronomicalUnits, parsec, awgDiameter, landMiles, lightSeconds, lightYears, meters, nauticalMiles, thous, mils, points, twips.
Mass Unit[Bearbeiten]
- Physic::Mass
- The base unit ("kg").
- Physic::Mass ounces
- Returns the "Ounces" unit; a converting unit which prints as "oz".
- Physic::Mass pounds
- Returns the "Pounds" converting unit which prints as "lb".
- Physic::Mass troyOunces
- Returns the "TroyOunces" converting unit.
- Physic::Mass carat
- Returns the "Carat" converting unit.
- Physic::Mass atomicMassUnits
- Returns the "AtomicMassUnits" converting unit.
- more mass converting units are returned by: daltons, grams, kiloGrams, kiloTonnes, megaTonnes, milliGrams, microGrams, nanoGrams, tonnes, troyPounds.
You may wonder what the kiloGrams converting unit is useful for, as the base unit's amount is already in kilograms. The difference is that the base unit will print values with a prefix (milli, micro, kilo etc.) whereas the kiloGram converting unit will always print kilograms.
Power Unit[Bearbeiten]
- Physic::Power
- The base SI unit. Prints as Watt.
- converting units are returned by: dBW, dBm, gigaWatt, kiloWatt, megaWatt, milliWatt
Pressure Unit[Bearbeiten]
- Physic::Pressure
- The base SI unit. Prints as Pascal.
- converting units are returned by: atmospheres, technicalAtmospheres, bar, hectoPascal, mH2O (meter of water), mmHg (mm of mercury), pascal, psi and torr.
Temperature Unit[Bearbeiten]
- Physic::Temperature
- The base SI unit. Prints as Kelvin.
- converting units are returned by: celsius, fahrenheit, rankine
Time Unit[Bearbeiten]
- Time durations are either represented by the already existing standard Smalltalk class "TimeDuration" or by the Time unit in the Physic namespace. Mixed arithmetic operations involving TimeDurations and PhysicalValues are transparently returning correct unit values. However, TimeDuration has a limitation in that it can only represent times down to the picosecond range, which might be not enough for high energy physic computations. Please use Physic::Time in this case.
- Physic::Time
- The base SI unit. Prints as Seconds.
- converting units are returned by: days, microSeconds, milliSeconds, seconds, weeks, years
Velocity Unit[Bearbeiten]
- Physic::Velocity
- The base SI unit. Prints as Meter per Second.
- converting units are returned by: beaufort, centiMetersPerSecond, kiloMetersPerHour, kiloMetersPerSecond, knots, metersPerHour, milesPerHour
Voltage Unit[Bearbeiten]
- Physic::Voltage
- The base SI unit. Prints as Volts.
- converting units are returned by: milliVolts, microVolts, nanoVolts, kiloVolts, dBV, dBu
Volume Unit[Bearbeiten]
- Physic::Volume
- The base SI unit. Prints as Cubic Meter.
- converting units are returned by: centiLiters, cubicInches, cubicMeters, deciLiters, fluidOuncesGB, fluidOuncesUS, gallonsGB, gallonsUS, hectoLiters, liters, milliLiters, barrels, barrelsIMP, barrelsUS (barrels are oil aka "blue barrels")
Per Unit Detailed API[Bearbeiten]
Notice the receiver of expressions in the following per-unit documentation.
If you read "number something", it means that you can send any number instance the "something" message.
And you will get an instance of the corresponding unit value as result.
For example:
2 gram
or
3.0 gram
or
(1/2) kiloGram
will all return corresponding mass value.
If you read "aMass something", it means that you can send the "something" message to a unit value instance (eg. a mass) and get some other representation of it as result.
Finally, if you read "aUnit something", it means that you can send the "something" message to a physical unit (not a physical value).
Mass[Bearbeiten]
Mass is measured in units of Kilogram, and the default printing is in "kg", "g", "mg", "ng" or whatever the print function considers appropriate.
The following operations return an instance of a mass (i.e. a value with a unit of "Mass") all of which will print themself as base units:
Instance Creation
- aNumber kiloGram
aNumber kilo gram
- Generates a mass-value of n kilograms.
Same asn kilo gram
(using SI prefix message).
- Generates a mass-value of n kilograms.
- aNumber gram
- Generates a mass-value of n grams.
- aNumber milliGram
aNumber milli gram
- Generates a mass-value of n milligrams.
Same asn milli gram
. (using SI prefix message)
- Generates a mass-value of n milligrams.
- aNumber microGram
aNumber micro gram
- Generates a mass-value of n micrograms.
Same asn micro gram
(using SI prefix message).
- Generates a mass-value of n micrograms.
- aNumber nano gram
- All SI prefixes as listed above.
- aNumber pounds
- Generates a mass-value of n pounds. A pound is defined as 453.59237 gram.
- aNumber ounces
- Generates a mass-value of n ounces. An ounce is defined as 28.35 g.
- aNumber troyOunces
- aNumber troy ounces
- Generates a mass-value of n troy ounces. These are used with metals (esp. gold) (31.1034768 g)
- aNumber imperial ton
- Generates a mass-value of 1016.05 kg (2240 lb)
- Also possible: imperial barrel, bushel, cup, floz, fluidOunce, gallon, hp, nauticalMile, pint, quart, tablespoon, teaspoon, ton
- aNumber american ton
- Generates a mass-value of 907.2 kg (2000 lb)
- Also possible: american barrel, bushel, cup, fldr, fluidDram, floz, fluidOunce, gallon, hp, nauticalMile, pint, quart, tablespoon, teaspoon, ton
- aNumber metric ton
- Generates a mass-value of 1000 kg (2204 lb)
- Also possible: metric hp, pint, ton
Unit Conversion
- aMass asGrams
- Returns the original mass in a converted unit which enforces explicit printing in grams (i.e. without any SI scaling prefix).
- aMass asNanoGrams
- Same, but enforces explicit printing in nanograms ("ng").
- aMass asMicroGrams
- Enforces explicit printing in micrograms ("µg").
- aMass asMilliGrams
- Enforces explicit printing in milligrams ("mg").
- aMass asKiloGrams
- Enforces explicit printing in kilograms ("kg").
- aMass asTonnes
- Enforces explicit printing in (metric) tonnes ("t").
- aMass asKiloTonnes
- Enforces explicit printing in (metric) kilotonnes ("kt").
- aMass asMegaTonnes
- Enforces explicit printing in (metric) megatonnes ("Mt").
- aMass asGigaTonnes
- Enforces explicit printing in (metric) gigatonnes ("Gt").
- aMass asPounds
- Enforces explicit printing in pounds ("lb") One pound is 453.59237 g.
- aMass asCarat
- Enforces explicit printing in carat ("ct"). 1 carat is 200mg.
- aMass asOunces
- Enforces explicit printing in ounces ("oz"). These are british (imperial) ounces (28.35 g)
- aMass asTroyOunces
- Enforces explicit printing in troy ounces ("oz t"). These are used with metals (31.103 g)
- aMass asDaltons
- Enforces explicit printing in dalton ("Da"). 1 dalton is 1/12 of the C12 atom's mass (1.66053906892e-27 kiloGram).
- aMass asAtomicMassUnits
- Enforces explicit printing in atomic mass units ("amu"). One amu is 1.660539066605e-27Kg.
In a Formula ('...' asPhysicExpression value)
'100 kg'
- mass in Kilogram. Also recognized: 'mg', 'µg', 'ng', 't'
'100 lb'
- mass in pounds. Also recognized: 'oz', 'oz tr', 'us ton', 'imp ton'
Length[Bearbeiten]
Length is measured in Meters, and the default printing is in "m", "km", "mm", "nm" or whatever the print function considers appropriate.
Instance Creation
- aNumber meter
- Generates a length-value of n meters.
- aNumber centiMeter
aNumber centi meter
- Generates a length-value of n centimeters.
Same asn centi meter
.
- Generates a length-value of n centimeters.
- aNumber milliMeter
aNumber milli meter
- Generates a length-value of n millimeters.
Same asn milli meter
.
- Generates a length-value of n millimeters.
- aNumber microMeter
aNumber micro meter
- Generates a length-value of n micrometers.
Same asn micro meter
.
- Generates a length-value of n micrometers.
- aNumber nanoMeter
aNumber nano meter
- Generates a length-value of n nanometers.
Same asn nano meter
.
- Generates a length-value of n nanometers.
- aNumber kiloMeter
aNumber kilo meter
- Generates a length-value of n kilometers.
Same asn kilo meter
.
- Generates a length-value of n kilometers.
- aNumber inch
- Generates a length-value of n inches. An inch is 25.4 mm.
- aNumber inches
- Same as inch above (for readability)
- aNumber feet
- Generates a length-value of n feet. A foot is 12 inches or 0.3048 m.
- aNumber yards
- Generates a length-value of n yards. A yard is 36 inches or 0.9144 m.
- aNumber landMiles
- Generates a length-value of n land miles. A land mile is 5280 feet or 1609.344 m.
- aNumber nauticalMiles
- Generates a length-value of n nautical miles. A nautical mile is 1852 m (i.e. a US nautical mile, not to be confused with the obsolete british nautical mile, which is slightly longer).
- aNumber chineseMiles
- Generates a length-value of n chinese miles. A Chinese mile is 500 m.
- aNumber astronomicalUnits
- Generates a length-value of n astronomical units. An au is 149597870.7 km.
- aNumber lightSeconds
- Generates a length-value of n lightseconds. A ls is 299792.458 km.
- aNumber lightYears
- Generates a length-value of n lightyears. A ly is 9460730472580.8 km (exact by definition).
- aNumber parsec
- Generates a length-value of n parsec. A parsec is 3.26156377716705 ly.
- aNumber angstrom
- Generates a length-value of n angstroms. 1 Å = 0.1 nm = 10e−10 m.
Unit Conversion
- aLength asMeters
- Returns the original length but enforces explicit printing in meters (i.e. prevents scaling prefix when printed).
- aLength asMilliMeters / asMicroMeters / asNanoMeters / asCentiMeters
- Enforces explicit printing in millimeters ("mm"), micrometers ("µm"), nanometers ("nm") or centimeters ("cm").
- aLength asKiloMeters
- Enforces explicit printing in kilometers ("km").
- aLength asAngstrom
- Enforces explicit printing in angstrom ("Å").
- aLength asInches / asFeet / asYards / asThous
- Enforces explicit printing in inches ("in"), feet ("ft"), yards ("yd") or thous ("thou").
- aLength asFeetAndInches
- Enforces explicit printing in feet and inches (inches rounded to 1 fractional digit).
"1.80 meter asFeetAndInches"
will print itself as " 5′10.9″ "
- Enforces explicit printing in feet and inches (inches rounded to 1 fractional digit).
- aLength asFeetAndInchesRounded
- Enforces explicit printing in feet and rounded inches.
"1.80 meter asFeetAndInchesRounded"
will print itself as " 5′11″ "
- Enforces explicit printing in feet and rounded inches.
- aLength asAWGDiameter
- Enforces explicit printing in american wire gauge units ("AWG").
- aLength asLandMiles
- Enforces explicit printing in land miles ("mi"). One land mile is 1.609344 km.
- aLength asNauticalMiles
- Enforces explicit printing in nautical miles ("NM"). One nautical mile is 1.852 km.
- aLength asLightYears
- Enforces explicit printing in lightyears ("ly"). A light year is 9460730472580.8 km.
- aLength asLightSeconds
- Enforces explicit printing in lightseconds ("ls"). A light second is 299792.458 km.
- aLength asAstronomicalUnits
- Enforces explicit printing in astronomicalUnits ("au"). An astronomical unit is 149597870.7 km.
- aLength as:(Physic::PhysicalUnit unitNamed:'Mil')
- Enforces explicit printing in mil. A mil is 1/1000 of an inch. Usage of mils is not recommended, as it may be confused with millimeter. You can use the synonym "Thou" instead, which avoids this.
In a Formula ('...' asPhysicExpression value)
'100 m'
- length in Meter. Also recognized: 'km', 'cm', 'mm', 'µm', 'nm', pm'
'100 mi'
- length in Miles. Also recognized: 'in', 'ft', 'yd', 'mil', 'twip'
'10 Å'
- length in Angstrom.
'1 au'
- length in Astronomical Units. Also: 'ly', 'ls', 'pc'
Angle[Bearbeiten]
Angles are measured in Radians, and the default printing is in "rad".
The following operations return an instance of angle:
Instance Creation
- aNumber radians
- Generates an angle of n radians.
- aNumber degrees
- Generates an angle of n degrees (which prints itself as radians)
- Notice that Number can also compute the raw value (as scalar number) with "degreesToRadians" and "radiansToDegrees".
Unit Conversion
- anAngle asDegrees
- Returns the same angle but enforces explicit printing in Degrees.
- anAngle asRadians
- Returns the same angle but enforces explicit printing in Radians (i.e. to convert back from above degrees value).
- anAngle asArcSec
- Returns the same angle but enforces explicit printing in arc seconds.
- anAngle asArcMin
- Returns the same angle but enforces explicit printing in arc minutes.
- anAngle asDegreeAndMinAndSec
- Returns the same angle but enforces explicit printing as d°m′s″
(e.g. "90.1234 degrees asDegreeAndMinAndSec" => 90°7′24″).
- Returns the same angle but enforces explicit printing as d°m′s″
- anAngle asGon
- Returns the same angle but enforces explicit printing in Gon (90 degrees = 100 gon).
Trigonometric
- anAngle sin
- Angles understand the typical trigonometric messages sin, cos, tan, cot (cotangent) and csc (cosecant).
- (Eg. you can write "45 degrees sin" to get 0.707106781186547)
Temperature[Bearbeiten]
Temperature is measured in Kelvin, and the default printing is in "K".
Instance Creation
- aNumber kelvin
- Generates an temperature-value of n Kelvin.
- aNumber degreesCelcius
- Generates an temperature-value of n degrees Celsius.
- aNumber degreesFahrenheit
- Generates an temperature-value of n degrees Fahrenheit.
- aNumber rankine
- Generates an temperature-value of n degrees Rankine.
Unit Conversion
- aTemperature asFahrenheit
- Returns the original temperature but enforces explicit printing in Fahrenheit.
- aTemperature asCelsius
- Enforces explicit printing in degrees Celsius.
- aTemperature asRankine
- Enforces explicit printing in Rankine.
- aTemperature blackBodyWaveLength
- The wavelength corresponding to the temperature (returns a length).
In a Formula ('...' asPhysicExpression value)
900 K'
- temperature in Kelvin.
900 °F'
- temperature in Fahrenheit.
900 °C'
- temperature in Celsius.
Frequency[Bearbeiten]
Frequency is measured in Hertz, and the default printing is in "Hz", "kHz", "MHz" or whatever the print function chooses.
Instance Creation
- aNumber hertz
- Generates a frequency-value of n hertz.
- aNumber kiloHertz
aNumber kilo hertz
- Generates a frequency-value of n kilohertz.
Same asn kilo hertz
.
- Generates a frequency-value of n kilohertz.
- aNumber megaHertz
aNumber mega hertz
- Generates a frequency-value of n megahertz.
Same asn mega hertz
.
- Generates a frequency-value of n megahertz.
- aNumber gigaHertz
aNumber giga hertz
- Generates a frequency-value of n gigahertz.
Same asn giga hertz
.
- Generates a frequency-value of n gigahertz.
- Physic::Frequency noteName: aString
- Converts the name of a note (in international note notation) to a frequency.
For example,Physic::Frequency noteName: 'A4'
generates 440Hz.
Valid note names are e.g. 'Bb4','C#5' or 'Db5'. I.e. the name within 'A' through 'G' followed by an optional 'b' (flat) or '#' sharp, followed by an optional octave number.
- Converts the name of a note (in international note notation) to a frequency.
- Physic::Frequency midiNr: anInteger
- Converts a Midi note number (0..127) to a frequency.
For example,Physic::Frequency midiNr: 69
generates 440Hz.
- Converts a Midi note number (0..127) to a frequency.
Unit Conversion
- 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").
Other
- aFrequency noteName
- The name of the nearest note (equal tempered).
- aFrequency midiNr
- The nearest Midi note number.
- aFrequency addSemitones: nrOfSemitones
- Returns the frequency nrOfSemitones higher (or lower, if negative).
- aFrequency addOctaves: nrOfOctaves
- Returns the frequency nrOfOctaves higher (or lower, if negative).
Energy[Bearbeiten]
Energy is measured in Joule, and the default printing is in "J", "kJ" or whatever the print function chooses as reasonable scale.
Many domains have their own preferred unit to use (atom physics use electron volts, energy industry uses wattHours and the oil industry uses btu).
Instance Creation
- aNumber joule
- Generates an energy-value of n joule.
- aNumber kiloJoule
aNumber kilo joule
- Generates an energy-value of n kilojoule.
Same asn kilo joule
.
- Generates an energy-value of n kilojoule.
- aNumber megaJoule
aNumber mega joule
- Generates an energy-value of n megajoule.
Same asn mega joule
.
- Generates an energy-value of n megajoule.
- aNumber wattHours
- Generates an energy-value of n wattHours.
Same asn watt * 1 hours
.
- Generates an energy-value of n wattHours.
- aNumber kiloWattHours
aNumber kilo wattHours
- Generates an energy-value of n kiloWattHours.
Same asn kilo wattHours
and also the same asn kilo watt * 1 hours
.
- Generates an energy-value of n kiloWattHours.
- aNumber megaWattHours
aNumber mega wattHours
- Generates an energy-value of n megaWattHours.
Same asn mega wattHours
and also the same asn mega watt * 1 hours
.
- Generates an energy-value of n megaWattHours.
- aNumber electronVolts
- Generates an energy-value of n electronVolts.
- aNumber calories
- Generates an energy-value of n calories.
- aNumber kiloCalories
aNumber kilo calories
- Generates an energy-value of n kcal.
Same asn kilo calories
.
- Generates an energy-value of n kcal.
- aNumber btu
- Generates an energy-value of n BTUs (British Thermal Units). 1 btu is 1055.06 J.
Unit Conversion
- anEnergy asElectronVolts
- Present (i.e. prints) as electronVolts ("eV")
- anEnergy asKiloWattHours
- Present as kiloWattHours ("kWh")
- anEnergy asMegaWattHours
- Present as megaWattHours ("mWh")
- anEnergy asGigaWattHours
- Present as gigaWattHours ("gWh")
- anEnergy asCalories
- Present as calories ("cal")
- anEnergy asKiloCalories
- Present as kilo calories ("kcal")
- anEnergy asBTUs
- Present as BTUs (British Thermal Units)
- anEnergy asTCEs
- Present as TCEs (Ton of Coal Equivalents)
In a Formula ('...' asPhysicExpression value)
'100 J'
- power in joule. Also recognized: 'kJ', 'MJ', 'GJ', 'Nm', 'eV', 'keV', 'MeV', 'cal', 'kcal', 'btu', 'Wh', 'kWh', 'MWh', 'GWh', 'TWh'
Power[Bearbeiten]
Power is a derived unit measured in Watt, and the default printing is in "W", "kW" or whatever the print function chooses as reasonable scale. Instances of "Power" are returned e.g. when multiplying an electric current by a voltage. Notice that there is a difference between VA and W in alternating current circuits. Here, Watt refers to the active power or power in direct current circuits (or instantaneous power values) .
Instance Creation
- aNumber watt
- Generates a power-value of n watt.
- aNumber milliWatt
- Generates a power-value of n milliWatt.
Same as "n milli watt
".
- Generates a power-value of n milliWatt.
- aNumber kiloWatt
- Generates a power-value of n kiloWatt.
Same as "n kilo watt
".
- Generates a power-value of n kiloWatt.
- aNumber megaWatt
- Generates a power-value of n megaWatt.
Same as "n mega watt
".
- Generates a power-value of n megaWatt.
- aNumber gigaWatt
- Generates a power-value of n gigaWatt.
Same as "n giga watt
".
- Generates a power-value of n gigaWatt.
- aNumber teraWatt
- Generates a power-value of n teraWatt.
Same as "n tera watt
".
- Generates a power-value of n teraWatt.
- aNumber metric hp
- Generates a power-value of n metric horsePower (PS). Roughly 735.5 watt.
- aNumber imperial hp
- Generates a power-value of n imperial horsePower (hp). Roughly 745.7 W watt.
Unit Conversion
- aPower asMicroWatt
- Presents itself as µW
- aPower asMilliWatt
- Presents itself as mW
- aPower asKiloWatt
- Presents itself as kW
- aPower asMegaWatt
- Presents itself as MW
- aPower asGigaWatt
- Presents itself as GW
- aPower asTeraWatt
- Presents itself as TW
- aPower asDBm
- Presents itself as decibel based on milliwatt (1 mW is 0.0 dBm; 1 W is 30.0 dBm)
- aPower asDBW
- Presents itself as decibel based on watt (1 W is 0.0 dBW; 1 kW is 30.0 dBW)
In a Formula ('...'asPhysicExpression value)
'100 W'
- power in watt. Also recognized: 'mW', 'µW', 'kW', 'MW', 'GW', 'hp imp', 'p metric'
Force[Bearbeiten]
Force is measured in Newton, and by default printed as such. Instances are created e.g. when multiplying a mass by an acceleration (in Smalltalk: "1 kg * 10 meters / 1 seconds squared").
Instance Creation
- aNumber newton
- Generates a force-value of n newton.
- Physic::Force kilopond: kpNumber
- Force from a given Kilopond amount. Notice that the Kilopond is no longer allowed (since 1978). So this should only be used when reading/converting old historic data.
- Physic::Force gramForce unitAmount: gfNumber
- Returns a force value of gfNumber gramForce (gf). Notice that the "gramForce" message sent to the Force class returns the GramForce unit (not a value). Then, that unit gets the "unitAmount:" message, which returns a physical value (gf).
Unit Conversion
- aForce asGramForce
- Presents itself as gf
- aForce asTonForce
- Presents itself as tf (metric tons of force)
- aForce asPoundsForce
- Presents itself as lbf
- aForce asKiloNewton
- Presents itself as kN
- aForce asMilliNewton
- Presents itself as mN
- aForce asNewton
- Presents itself as N (i.e. without scale prefix)
Area[Bearbeiten]
Area is a derived unit based on length in meters and measured in square meter. The default printing is in "m²". Instances of "Area" are created e.g. when multiplying two length values or when dividing a volume by a length.
Instance Creation
- aNumber squareMeter
- Generates an area-value of n square meters (m²).
- aNumber squareMilliMeter
- Generates an area-value of n square millimeters.
- aNumber squareKiloMeter
- Generates an area-value of n square kilometers (1000*1000 m²).
- aNumber hectare
- Generates an area-value of n hectares. Same as
n hecto are
or 10000 m².
- Generates an area-value of n hectares. Same as
- aNumber are
- Generates an area-value of n ares. 1 are being 100 m².
- aNumber squareMiles
- Generates an area-value of n square miles. 1 sq mi being 2589988.110336 m².
- aNumber squareFeet
- Generates an area-value of n square feet. 1 sq ft being 0.0929 m².
- aNumber acres
- Generates an area-value of n acres. 1 acre being 4046.856 m².
Conversion
- anArea asAre
- Presents itself as are (1 are = 100 m²)
- anArea asAWG
- Presents itself as american gauge units (wire thickness)
- anArea asHectare
- Presents itself as hectare ("ha")
- anArea asSquareKiloMeters
- Presents itself as square kilometer ("km²")
- anArea asSquareMeters
- Presents itself as square meter ("m²") without scale prefix
- anArea asSquareFeet
- Presents itself as square feet ("sq ft")
- anArea asAcres
- Presents itself as acres ("ac")
- anArea asSquareMiles
- Presents itself as square miles ("sq mi") (based on a land mile being 1609.344 m)
Volume[Bearbeiten]
Volume is a derived unit based on length in meters and measured in cubic meter. The default printing is in "m³", although the print function may choose to print in liters "l", or milli liters "ml" etc.
Instances of "Volume" are created e.g. when multiplying an area by a length or when cubing a length.
Instance Creation
- aNumber cubicMeter
aNumber cubic meter
- Generates an volume-value of n cubic meters (1000 l). The alternative "1 cubic meter" uses the "cubic" prefix.
- aNumber liter
- Generates an volume-value of n liters.
- aNumber milliLiter
- Generates a volume-value of n milliliters.
Same as "n milli liter
".
- Generates a volume-value of n milliliters.
- aNumber hectoLiter
- Generates a volume-value of n hectoliters.
Same as "n hecto liter
".
- Generates a volume-value of n hectoliters.
- aNumber barrel
aNumber american barrel
- Generates a volume of n barrels (oil volume measurement). 1 (oil) barrel is 158.987 liters. This is an US oil barrel (aka "blue barrel"), which is different from an imperial barrel and also different from beer/wine barrels.
- aNumber flozIMP
aNumber flozGB
aNumber british floz
aNumber imperial floz
- Generates a volume of n imperial fluid ounces (0.02841 liter or 28.4130625 ml).
- number flozUS
number american floz
- Generates a volume of n US fluid ounces (0.02957 liter or 29.5735295625 ml).
- aNumber pintIMP
aNumber pintGB
aNumber british pint
aNumber imperial pint
- Generates a volume of n imperial pints (568.26125 ml).
- aNumber pintUS
aNumber american pint
- Generates a volume of n US pints (473.176473 ml). It seems that british drinkers get more for the pint ;-)
- aNumber quartIMP
aNumber quartGB
aNumber british quart
aNumber imperial quart
- Generates a volume of n imperial quarts (1.1365 liter).
- aNumber quartUS
aNumber american quart
- Generates a volume of n US quarts (946.353 ml).
- aNumber gallonsIMP
aNumber gallonsGB
aNumber british gallons
aNumber imperial gallons
- Generates a volume of n imperial gallons (4.5461 liter).
- aNumber gallonsUS
aNumber american gallons
- Generates a volume of n US gallons (3.7854 liter).
Converting
- aVolume asCubicMeters
- Presents itself as cubic meters ("mˆ3") (not as "ml" or "l")
- aVolume asLiters
- Presents itself as liters ("l"). (not as "ml" or "mˆ3")
- aVolume asHectoLiters
- Presents itself as hectoliters ("hl") (not as "ml", "l" or "mˆ3")
- aVolume asMilliLiters
- Presents itself as milliliters ("ml") (not as "l" or "mˆ3")
- aVolume asCentiLiters
- Presents itself as centiliters ("cl") (not as "l" or "mˆ3")
- aVolume asDeciLiters
- Presents itself as deciliters ("dl") (not as "l" or "mˆ3")
- aVolume asCubicInches
- Presents itself as cubic inches ("cuin")
- aVolume asFlozGB
- Presents itself as imperial fluid ounces ("imp fl oz")
- aVolume asFlozUS
- Presents itself as US fluid ounces ("us fl oz")
- aVolume asGallonsGB
- Presents itself as imperial gallons ("imp ga")
- aVolume asGallonsUS
- Presents itself as US gallons ("us ga")
Print Setup
- Physic::Volume literAbbrev: 'L'
- configure to print "L" (upper case) instead of "l" (lower case letter "L").
(NIST recommendation in US, to avoid confusion with the digit '1'). Other useful arguments are 'ℓ'or 'ltr'.
- configure to print "L" (upper case) instead of "l" (lower case letter "L").
In a Formula ('...'asPhysicExpression value)
'100 L'
- volume in Liter. Also recognized: 'dL', 'cL', 'ml', 'µL', 'hL'
'100 gal'
- volume in US gallons. Also recognized: 'bbl','floz', with optional modifier: american ('gal us') and imperial ('gal imp').
Velocity (Speed)[Bearbeiten]
Velocity is a derived unit based on length in meters and measured in meters per second. The default printing is in "m/s". Instances of "Velocity" are created e.g. when dividing a length by a time duration.
Instance Creation
- aNumber meterPerSecond
- Generates a velocity of n meters per second.
- aNumber kiloMeterPerHour
- Generates a velocity of n km per hour.
- aNumber milesPerHour
- Generates a velocity of n mph.
- aNumber knots
- Generates a velocity of n nautical miles per hour.
- Physic::NatureConstants lightspeed
- Speed of light in vacuum
- Physic::NatureConstants soundspeed
- Speed of sound (in dry air at 20°C)
Conversion
- aVelocity asKiloMetersPerHour
- Presents itself as km/h
- aVelocity asMilesPerHour
- Presents itself as mph
- aVelocity asKnots
- Presents itself as nautical knots (kn). 1 knot being 0.514 m/s or 1.852 km/h ("1.0 knots asKiloMetersPerHour").
In a Formula ('...'asPhysicExpression value)
'100 m/s'
- speed in Meter per second. Also recognized: 'km/h', 'cm/s', 'mph', 'mi/h'
'100 kn'
- speed in Knots.
Acceleration[Bearbeiten]
Velocity is a derived unit based on length in meters and measured in meters per second per second. The default printing is in "m/s²". Instances of "Acceleration" are created e.g. when dividing a velocity by a time duration.
Instance Creation
- aNumber metersPerSecondPerSecond
- Generates an acceleration of n m/s².
- Physic::NatureConstants earthGravity
- Returns 9.80665 m/s²
- Physic::NatureConstants['planets']['earth']['gravity'|
- also returns 9.80665 m/s²
Conversion
- anAcceleration asGForce
- Presents itself as "g" (multiples of 9.81m/s²).
Queries
- anAcceleration distanceAfter: aTimeDuration
- Computes the distance travelled when a constant acceleration is applied for some time.
- anAcceleration speedAfter: aTimeDuration
- Computes the speed when a constant acceleration is applied for some time.
Pressure[Bearbeiten]
Pressure is a derived unit measured in Pascal. The default printing is in "Pa". Instances of "Pressure" are created e.g. when dividing a force by an area.
Instance Creation
- aNumber pascal
- Generates a pressure value of n pascal.
- aNumber hectoPascal
- Generates a pressure value of n hectoPascal.
Same as "n hecto pascal
".
- Generates a pressure value of n hectoPascal.
Conversion
- aPressure asAtm
- Presents itself as atm (atmospheres)
- aPressure asBar
- Presents itself as bar
- aPressure asHectoPascal
- Presents itself as hPa
- aPressure asPascal
- Presents itself as Pa
- aPressure asPSI
- Presents itself as psi (pounds per square inch)
- aPressure asTorr
- Presents itself as torr
- aPressure asMmHg
- Presents itself as mmHg (millimeter of mercury). Same magnitude as torr, but this is typically used in medical domains.
In a Formula ('...'asPhysicExpression value)
'100 Pa'
- pressure in pascal. Also recognized: 'hPa', 'kPa', 'MPa', 'GPa', 'mPa', 'bar', 'atm', 'psi', 'mmH2O', 'mmHg', 'torr'
Voltage[Bearbeiten]
Voltage is a derived unit measured in Volt. The default printing is in "V", "mV", "kV" as appropriate.
Instance Creation
- aNumber volts
- Generates an electrical voltage of n volts.
- aNumber milliVolt
aNumber milli volt
- Generates a voltage of n millivolt.
- aNumber microVolt
aNumber micro volt
- Generates a voltage of n microvolt.
- aNumber kiloVolt
aNumber kilo volt
- Generates a voltage of n kilovolt.
Conversion
- aVoltage asDBV
- Presents itself as as DBV (decibel voltage Lv)
- aVoltage asDBu
- Presents itself as as DBu (decibel voltage Lu)
- aVoltage asKiloVolts
- Presents itself as kV
- aVoltage asMilliVolts
- Presents itself as mV
- aVoltage asMicroVolts
- Presents itself as µV
- aVoltage asNanoVolts
- Presents itself as nV
- aVoltage asVolts
- Presents itself as V (without scale prefix)
Electric Current[Bearbeiten]
A derived unit measured in Ampere. The default printing is in "A", "mA", "kA" as appropriate. Instances of "Current" are created e.g. when dividing an electric charge by a time duration.
Instance Creation
- aNumber ampere
- Generates an electric current of n ampere.
- aNumber milliAmpere
aNumber milli ampere
- Generates an electric current of n milliampere.
- aNumber microAmpere
aNumber micro ampere
- Generates an electric current of n microampere.
Conversion
- aCurrent asKiloAmperes
- Presents itself as "kA"
- aCurrent asMilliAmperes
- Presents itself as "mA"
- aCurrent asMicroAmperes
- Presents itself as "uA"
- aCurrent asNanoAmperes
- Presents itself as "nA"
- aCurrent asPicoAmperes
- Presents itself as "pA"
- aCurrent asAmperes
- Presents itself as "A"
Electric Resistance[Bearbeiten]
A derived unit measured in Ohm. The default printing is in "Ω", "kΩ", "MΩ" as appropriate.
Instance Creation
- aNumber ohm
- Generates an electric resistance of n ohm.
- aNumber kiloOhm (or kilohm)
- Generates an electric resistance of n kilo Ohm.
- aNumber megaOhm
- Generates an electric resistance of n megaOhm.
- Physic::ElectricResistance colorCode: #(name1 name2 name3 [name4])
- Generates an electric resistance given a resistor's color code. The argument must be a 3 or 4 element collection (array), and the name_i elements must be color name symbols, i.e. one of {black, brown, red, orange, yellow, green, blue, violet, grey, white).
For example, "Physic::ElectricResistance' colorCode:#(yellow violet red)" returns 4700 Ω.
- Generates an electric resistance given a resistor's color code. The argument must be a 3 or 4 element collection (array), and the name_i elements must be color name symbols, i.e. one of {black, brown, red, orange, yellow, green, blue, violet, grey, white).
Conversion
- aResistance asKiloOhms (or asKilohms)
- prints as "kΩ".
- aResistance asMegaOhms
- prints as "MΩ".
- aResistance asOhms
- prints as "Ω".
- aResistance asMilliOhms
- prints as "mΩ".
Additional Arithmetic Operations
- aResistance1 | aResistance2
- Computes the resistance of resistors in parallel (as opposed to "+" which adds the values and thus computes resistors in series)
Electric Capacitance[Bearbeiten]
A derived unit measured in Farad. The default printing is in "F", "uF", "nF", "pF" as appropriate.
Instance Creation
- aNumber farad
- Generates an electric capacitance of n farad.
- aNumber microFarad
- Generates an electric capacitance of n microfarad.
- aNumber nanoFarad
- Generates an electric capacitance of n nanofarad.
- aNumber picoFarad
- Generates an electric capacitance of n picofarad.
Conversion
- aCapacitance asMicroFarads
- Presents itself as "uF"
- aCapacitance asNanoFarads
- Presents itself as "nF"
- aCapacitance asPicoFarads
- Presents itself as "pF"
- aCapacitance asFarads
- Presents itself as "F"
Additional Arithmetic Operations
- aCapacitance1 | aCapacitance2
- Computes the capacitance of caps in parallel (same as "+" here)
Electric Charge[Bearbeiten]
A unit measured in Coulomb. The default printing is in "C". Instances of "Charge" are created e.g. when multiplying an electric current by a time duration.
Instance Creation
- aNumber coulomb
- Generates an electric charge of n coulomb.
Conversion
- aCharge asAmpereSeconds
- Presents itself as "As" (which is also a coulomb, but "As" might be preferred in some domains)
- aCharge asAmpereHours
- Presents itself as "Ah"
- aCharge asElementaryCharges
- Presents itself as "q".
1 coulomb corresponds to 6.241e+18 elementary charges
- Presents itself as "q".
- aCharge asNumberOfElectrons
- Returns the above as a scalar number
Inductance[Bearbeiten]
A unit measured in Henry (H).
Instance Creation
- aNumber henry
- Generates an inductance of n henry.
Conversion
- anInductance asMilliUnitValue
- Presents itself as "mH"
- anInductance asMicroUnitValue
- Presents itself as "µH"
Additional Arithmetic Operations
- anInductance1 | anInductance2
- Computes the inductance of coils in parallel (as opposed to "+" which adds the values and thus computes coils in series)
LuminousIntensity[Bearbeiten]
A unit measured in Candela (cd).
Instance Creation
- aNumber candela
- Generates a luminousIntensity of n candela.
Luminance[Bearbeiten]
A unit measured in Lux (lx). Results from dividing a luminous intensity by an area.
Instance Creation
- aNumber lux
- Generates a luminance of n lux.
MagneticFlux[Bearbeiten]
A unit measured in Weber (Wb).
Results from multiplying a voltage by a time.
MagneticFluxDensity[Bearbeiten]
A unit measured in Tesla (T).
Results from dividing a magnetic flux by an area.
CurrentDensity[Bearbeiten]
A unit measured in A/m².
Results from dividing an electric current by an area.
Viscosity[Bearbeiten]
DynamicViscosity unit measured in Poise (P) and KinematicViscosity measured in Stokes (St).
Electric Conductance[Bearbeiten]
A unit measured in Siemens (S) which is s³·m⁻²·kg⁻¹·A² (dimension T³·L⁻²·M⁻¹·I²).
This is the reciprocal of the electric resistance.
Mass Density[Bearbeiten]
A unit measured in kg/m³ (dimension L⁻³·M). Instances are created e.g. when dividing a mass by a volume.
Conversion
- aMassDensity asGramPerCubicCentimeter
- Presents itself as g/cm³. For example:
- massSun := Physic::NatureConstants['sun']['mass'].
- volumeSun := Physic::NatureConstants['sun']['Volume'].
- (massSun / volumeSun) asGramPerCubicCentimeter
- => 1.41028368794326 g/cm³
- Presents itself as g/cm³. For example:
English Engineering and Imperial Units (EEU)[Bearbeiten]
See English Engineering Units and Imperial and US customary measurement systems.
EEU/Imperial Length[Bearbeiten]
Unit Access
- PhysicalUnit::Length inches
- Returns a unit which represents its values as "in"
- PhysicalUnit::Length feet
- Returns a unit which represents its values as "ft"
- PhysicalUnit::Length yards
- Returns a unit which represents its values as "yd"
- PhysicalUnit::Length thous
- Returns a unit which represents its values as "thous"
- PhysicalUnit::Length landMiles
- Returns a unit which represents its values as "mi"
- PhysicalUnit::Length nauticalMiles
- Returns a unit which represents its values as "nmi"
Instance Creation
- (PhysicalUnit::Length feet) unitAmount: n
- Generates a length of n feet.
- someUnit unitAmount: n
- Once you have any units at hand, you'll get a physical value with <aUnit> unitAmount: <n>
Number Protocol
- aNumber feet (prints itself with SI unit 'm')
- aNumber feet asFeet (prints itself with unit 'ft')
- aNumber inches (prints itself with SI unit 'm')
- aNumber inches asInches (prints itself with unit 'in')
- aNumber yards
- aNumber yards asYards (prints itself with unit 'yd')
- aNumber landMiles
- aNumber landMiles asLandMiles (prints itself with unit 'mi')
- aNumber nauticalMiles
- aNumber nauticalMiles asNauticalMiles (prints itself with unit 'nmi')
EEU/Imperial Area[Bearbeiten]
Unit Access
- PhysicalUnit::Area squareInches
- Returns a unit which represents its values as "sq in"
- PhysicalUnit::Area squareFeet
- Returns a unit which represents its values as "sq ft"
- PhysicalUnit::Area squareMiles
- Returns a unit which represents its values as "sq mi"
- PhysicalUnit::Area acres
- Returns a unit which represents its values as "acre"
Number Protocol
- aNumber square inches (prints itself with SI unit 'm²')
- aNumber square inches asSquareInches (prints itself with unit 'sq in')
- aNumber square feet (prints itself with SI unit 'm²')
- aNumber square feet asSquareFeet (prints itself with unit 'sq ft')
- aNumber square miles (prints itself with SI unit 'm²')
- aNumber square miles asSquareFeet (prints itself with unit 'sq mi')
- aNumber acres (prints itself with SI unit 'm²')
- aNumber acres asAcres (prints itself with unit 'acre')
EEU/Imperial Volume[Bearbeiten]
Unit Access
- PhysicalUnit::Volume cubicInches
- Returns a unit which represents its values as "cu in"
- PhysicalUnit::Volume cubicFeet
- Returns a unit which represents its values as "cu ft"
- PhysicalUnit::Volume cubicYards
- Returns a unit which represents its values as "cu yd"
- PhysicalUnit::Volume squareMiles
- Returns a unit which represents its values as "sq mi"
- PhysicalUnit::Volume gallonsIMP
- Returns a unit which represents its values as imperial gallons "imp gal"
- PhysicalUnit::Volume gallonsUS
- Returns a unit which represents its values as US gallons "US gal"
- PhysicalUnit::Volume pintsIMP
- Returns a unit which represents its values as imperial pints "imp pt"
- PhysicalUnit::Volume pintsUS
- Returns a unit which represents its values as US pints "US pt"
- PhysicalUnit::Volume barrelsIMP
- Returns a unit which represents its values as imperial barrels "bbl. imp"
- PhysicalUnit::Volume barrelsUS
- Returns a unit which represents its values as US pints "bbl."
Number Protocol
- aNumber cubic inches (prints itself with SI unit 'm³')
- aNumber cubic inches asCubicInches (prints itself with unit 'cu in')
- aNumber cubic feet (prints itself with SI unit 'm³')
- aNumber cubic feet asCubicFeet (prints itself with unit 'cu ft')
- aNumber cubic yards (prints itself with SI unit 'm³')
- aNumber cubic yards asCubicFeet (prints itself with unit 'cu yd')
- aNumber imperial pints (prints itself with SI unit 'm³')
- aNumber imperial pints asPintsIMP (prints itself with unit 'imp pt')
- aNumber american pints (prints itself with SI unit 'm³')
- aNumber american pints asPintsUS (prints itself with unit 'US pt')
- aNumber imperial gallons (prints itself with SI unit 'm³')
- aNumber imperial gallons asGallonsIMP (prints itself with unit 'imp gal')
- aNumber american gallons (prints itself with SI unit 'm³')
- aNumber american gallons asGallonsUS (prints itself with unit 'US gal')
- aNumber imperial barrels (prints itself with SI unit 'm³')
- aNumber imperial barrels asBarrelsIMP (prints itself with unit 'bbl. imp')
- aNumber american barrels (prints itself with SI unit 'm³')
- aNumber american barrels asBarrelsUS (prints itself with unit 'bbl.')
EEU/Imperial Mass[Bearbeiten]
Unit Access
- PhysicalUnit::Mass poundMass
- Returns a unit which represents its values as "lb"
- PhysicalUnit::Mass ounces
- Returns a unit which represents its values as "oz"
- PhysicalUnit::Mass troyOunces
- Returns a unit which represents its values as "oz t"
Number Protocol
- aNumber pounds (prints itself with SI unit 'kg')
- aNumber pounds asPounds (prints itself with unit 'lb')
- aNumber troyOunces (prints itself with unit 'kg')
- aNumber troyOunces asTroyOunces (prints itself with unit 'oz t')
EEU/Imperial Force[Bearbeiten]
Unit Access
- PhysicalUnit::Mass poundForce
- Returns a unit which represents its values as "lbf"
- PhysicalUnit::Mass poundal
- Returns a unit which represents its values as "pdl"
EEU/Imperial Power[Bearbeiten]
Unit Access
- PhysicalUnit::Mass poundForce
- Returns a unit which represents its values as "lbf"
- PhysicalUnit::Mass poundal
- Returns a unit which represents its values as "pdl"
EEU/Imperial Energy[Bearbeiten]
Unit Access
- PhysicalUnit::Mass btu
- Returns a unit which represents its values as "btu"
EEU/Imperial Temperature[Bearbeiten]
Unit Access
- PhysicalUnit::Temperature fahrenheit
- Returns a unit which represents its values as "°F"
- PhysicalUnit::Temperature rankine
- Returns a unit which represents its values as "°R"
Defining Additional Unit Converters[Bearbeiten]
You can define additional unit converters as ConvertedUnit as follows:
myUnit := Physic::ConvertedUnit name:unitName baseUnit:baseUnit unitString:unitString unitValueBlock:unitValueBlock baseUnitValueBlock:baseUnitValueBlock
Where
- baseUnit is the underlying base (SI) unit,
- unitString is the string used when printing,
- unitValueBlock is a Smalltalk block to compute the unit value from a base unit value and
- baseUnitValueBlock is a Smalltalk block to compute the base unit value from the unit value.
Example: Cubic Inch Unit[Bearbeiten]
For example, to get volumes printed as cubic inches, you could define 1):
cI := Physic::ConvertedUnit name:'CubicInches' baseUnit:(Physic::Volume) unitString:'in³' unitValueBlock:[:cubicMeters | cubicMeters * 61023.7440947323 ] baseUnitValueBlock:[:cubicInches| cubicInches / 61023.7440947323 ]
i.e. to convert from SI base-units, which are cubic meters, into the converted cubic inches, we have to multiply by 61023.7440947323.
And vice versa, we have to divide. 61023.7440947323 is the number of cubic inches per cubic meter.
Then create a new physical value for your volume with:
cI unitAmount:volumeInCubicMeters
Example: Gummy Bear Unit[Bearbeiten]
Or, to present a mass in units of gummy-bears, assuming one bear weighs 1.1g 2):,
bearUnit := Physic::ConvertedUnit name:'Haribo' baseUnit:(Physic::Mass) unitString:'bears' unitValueBlock:[:kiloGram| kiloGram * 1000 / 1.1] baseUnitValueBlock:[:bears| bears * 1.1 / 1000]
and then take a 150g bag of bears and ask it to print itself on an output stream:
bagOfBears := bearUnit baseUnitAmount:0.150. "/ 0.15 for 150g, because the base unit is kiloGram bagOfBears printOn:Transcript
gives:
=> "136.363636363636 bears"
Notice, that bearUnit ("Haribo") is still a unit of mass; we can add another kilogram to those bears:
bagOfBears + 1 kilo gram
and get more bears:
=> 1045.45454545455 bears
You can also convert any mass into gummy-bears:
(1 kiloGram as:bearUnit) floor
gives:
=> 909.0 bears
Notes:
1) this is only an example; you actually don't need that, as volumes already support conversion to cubicInches (see asCubicInches below)
2) the author does not know what the actual mass of a gummy bear is ;-)
Instance Creation via Number Operators[Bearbeiten]
The Number class hierarchy provides a number of instance creation messages for unit values. As described above, a frequency value can be created by sending a "hertz" message to any number:
440 hertz
The following lists a subset of messages which are provided in Number (for some, both abbreviations and british/US spelling versions are provided):
- Area
- acre, acres, are, hectare, squareMeter, squareCentiMeter, squareFeet, squareInches, squareKiloMeter, squareMiles, squareMilliMeter, squareYard.
- You can also use the "square" prefix with meter, feet, inches, yards, etc. As in "
10 square feet
".
- Energy
- btu, calories, electronVolts, wattHours,
- Frequency
- hertz, kiloHertz, megaHertz, gigaHertz, Hz, kHz, MHz, GHz
- Length
- angstrom, astronomicalUnits, centiMeter, chineseFeet, chineseMiles, feet, meter, yards, lightYears, miles, seaMiles, kiloMeter, milliMeter, ...
- Mass
- atomicMassUnits, gram, kiloGram, kg, microGram, troyPounds, troyOunces, ...
- You can use the "american"/"british"/"imperial"/"troy" prefixes on "ounces". As in "
2 troy ounces
".
- Pressure
- hectoPascal, torr, ...
- Temperature
- degreesCelsius, degreesFahrenheit, kelvin, ...
- Velocity
- centiMetersPerSecond
- Volume
- gallonsGB, gallonsUS, liter, litre, hectoLiter, hectoLitre, barrel, cubicInches, cubicMeter, cubicCentiMeter, cubicMilliMeter, cubicFeet, cubicKiloMeter, flozGB, flozUS, fluidOuncesGB, fluidOuncesUS, ...
- You can also use the "cubic" prefix with meter, feet, inches, etc. Eg. "
10 cubic feet
". - And you can use the "american"/"british"/"imperial" prefixes on "gallons", "pints", "quarts". Eg. "
1 british pint
".
- Data
- bits, bytes, kiloByte, megaByte, gigaByte, kibiByte, mebiByte, gibiByte, ...
- Electricity
- volt, ampere, ohm, coulomb, farad, ampereHours, watt, voltAmpere, henry, ...
- Other
- candela, becquerel, tesla, ...
For a full list, open a SystemBrowser, navigate to the ArithmeticValue class and select the "physics-unit converting" category.
All of those can be used with the kilo, mega, giga etc. prefixes.
Arithmetic[Bearbeiten]
Arithmetic on physical values will generate an appropriate physical value with its own unit. E.g., when multiplying a velocity by a time, you will get a distance, or when dividing a distance by a time, you will get a velocity.
The following lists some of the possible results. Be aware that the units are ignorant of any relativistic effects. They compute their values according to classical Newtonian mechanics.
Velocity Arithmetic[Bearbeiten]
distance = velocity * time
3 meterPerSecond => 3 m/s 1 meterPerSecond * 10 seconds => 10 m 10 kiloMetersPerHour * 30 minutes => 5000 m 30 meter / 2 seconds => 15 m/s 10 meter / 1 seconds * 20 seconds => 20 m
Acceleration Arithmetic[Bearbeiten]
speed = acceleration * time
1 meterPerSecondPerSecond * 10 seconds => 10 m/s (1 meterPerSecondPerSecond distanceAfter:1 hours) => 6480.0 km 1 meterPerSecond / 10 seconds => 0.1 m/s² 10 meter / 2 seconds / 5 seconds => 1 m/s² (9.81 meter / 1 seconds squared) * 1 hours => 70632 m/s
Mass Arithmetic[Bearbeiten]
force = mass * acceleration
1 kiloGram * 1 meterPerSecondPerSecond => 1 N 1 kilo gram * 1 meter / 1 seconds / 1 seconds => 1 N 1 kilo gram * 100 centi meter / 1 seconds squared => 1 N 1 newton / 2 kiloGram => (1/2) m/s²
Electric Arithmetic[Bearbeiten]
current = voltage / resistance
charge = voltage * capacitance
charge = current * time
10 volt / 220 ohm => 45.45 mA 150 ohm * 20 milliAmpere => 3 V 0.5 ampere * 0.5 seconds => 0.25 C 100.0 micro farad * 100 volt => 0.01 C 10.0 micro farad * 100 ohm => 1.0 ms (the RC time constant) 100 pico farad * 5 volt / 10 milli ampere => 50ns
Energy & Power Arithmetic[Bearbeiten]
10 ampere * 220 volt => 2200 W 10 ampere * 220 volt * 10 hours => 79.2 MJ 10 kiloWatt * 10 hours => 360.0 MJ (10 kiloWatt * 10 hours ) asKiloWattHours => 100 kWh
Math Functions and Trigonometric[Bearbeiten]
Angles respond to trigonometric operations:
45 degrees sin => 0.707106781186547 Float pi radian cos => -1.0
If useful, square and cubic root can be computed:
25 squareFeet sqrt => 1.524 m 25 squareFeet sqrt asFeet => 5.0 ft 5 feet * 5 feet. => 2.322576 m² 10 liter cbrt => 0.2154 m
Comparing[Bearbeiten]
If the unit's amount is a float, the usual float comparison problems arise (see chapter on comparing float numbers).
You should not compare physical values for equal values; instead give an accepted error range. Either as fraction (e.g. percentage) or in the number accepted eps steps:
25.0 squareFeet sqrt = 5 feet => false 25.0 squareFeet sqrt isAlmostEqualTo: 5 feet withError:0.00001 => true 25.0 squareFeet sqrt isAlmostEqualTo: 5 feet nEpsilon:2. => true
Rounding & Truncating[Bearbeiten]
Rounding and truncation operations are provided which generate a unit with the amount processed like the corresponding number operations:
1.0 meter floor => 1 m 1.1 meter floor => 1 m 1.7 meter floor => 1 m 1.0 meter ceiling => 1 m 1.1 meter ceiling => 2 m 1.7 meter ceiling => 2 m 1.0 meter rounded => 1 m 1.1 meter rounded => 1 m 1.7 meter rounded => 2 m 1.15 meter roundTo:0.1 => 1.1 m 1.15 meter roundTo:0.2 => 1.2 m 1.15 meter roundTo:0.5 => 1 m 1.04 meter roundTo:0.2 => 1 m 1.1 meter roundTo:0.2 => 1.2 m 2 meter negated => -2 meter (4/3) meter roundedToScale:0 => 1 m (4/3) meter roundedToScale:1 => 1.3 m (4/3) meter roundedToScale:2 => 1.33 m (4/3) meter roundedToScale:3 => 1.333 m (5/3) meter roundedToScale => 1.67 m (5/3) meter roundedToScale:0 => 2 m (5/3) meter roundedToScale:1 => 1.7 m (5/3) meter roundedToScale:2 => 1.67 m (5/3) meter roundedToScale:3 => 1.667 m
Be careful with roundedToScale: it will round the unit (which in the above case is meter). If the value is small (i.e. in the cm range), rounding to scale 2 will round to 1/100 meter, which might later print strange unexpected values. Thus it is best to convert the result into a desired range (i.e. asCentiMeters) and round this: eg:
15.012 centiMeter => 0.15012 m 15.0120 centiMeter roundedToScale:2 => 0.15 m 15.0120 centiMeter asCentiMeters roundedToScale:2 => 15.01 cm
Formula Evaluation[Bearbeiten]
Formulae can be parsed and further processed by use of the Physic::Parser class.
Physic::Parser
parse: aString
generates a parse tree for further processing
- aString asPhysicExpression
same
Physic::Parser
evaluate: aString
parses and evaluates
Generated parse trees can be further processed with:
- aParseTree value
evaluates the tree; variables are resolved to be units or nature constants
- aParseTree valueIn: aDictionary
evaluates the tree providing variable values
- aParseTree valueWith: anAssociation
evaluates the tree providing a single variable value in the form "( 'name' -> value )" (i.e. a Smalltalk Association instance).
- aParseTree valueWith: assoc1 [ with: assoc2 ...]
ditto, providing 2 values. Up to 4 values can be provided.
- aParseTree valueWithX: valueOfX
shortcut provided, since 'x' is such a common name.
- aParseTree simplify
simplifies a parsed formula (if possible)
- aParseTree derivate
generates a derivate
Formula Examples[Bearbeiten]
vars := Dictionary new. vars at:'a' put:10. vars at:'b' put:20. vars at:'c' put:30. (Physic::Parser parse:'a*x^2 + b*x + c') valueIn:vars => 10·x·x + 20·x + 30. (still a symbolic expression, because 'x' is unknown)
vars := Dictionary new. vars at:'a' put:10. vars at:'b' put:20. vars at:'c' put:30. vars at:'x' put:1. (Physic::Parser parse:'a*x^2 + b*x + c') valueIn:vars => 60 (a number)
"/ alternative (an inline object instead of a Dictionary) vars := { a: 10 . b: 20 . c: 30 . x : 2 }. (Physic::Parser parse:'a*x^2 + b*x + c') valueIn:vars => 110 (a number)
"/ alternative (individual values (up to 4 associations)) vars := { a: 10 . b: 20 . c: 30 . x : 2 }. ('a*x^2 + b*x + c' asPhysicExpression) valueWith:('a' -> 10) with:('b' -> 20) with:('c' -> 30) with:('x' -> 2). => 110 (a number)
('3*x^2 + 5*x + 17' asPhysicExpression) valueWithX:5 => 117
('a*x^2 + b*x + c' asPhysicExpression) derivate => 2·a·x + b
('sin(a*x) + cos(b*x)' asPhysicExpression) derivate => cos(a·x)·a - sin(b·x)·b
Equation Solving[Bearbeiten]
The solver can solve simple equations (but do not expect it to be a replacement for Mathematica ;-):
equation := 'a = 5*b + c' asPhysicExpression. equation solveFor:'b' => b = (a - c) / 5
(actually, it will give "b = (1/5)·(a - c)", which is equivalent)
For example, from the wellknown Formula "U = R * I",
equation := Physic::Parser parse:'U = R * I'.
we can derive:
equation2 := equation solveFor:'R'.
and get "R = U/I".
Of which the right side:
formulaForR := equation2 rightSide => U/I
Applying this formulaForR to concrete values:
formulaForR valueIn:{ 'U' -> 5 volt . 'I' -> 20 milliAmpere } => 250 Ω
Providing additional Formulas[Bearbeiten]
The framework's knowledge database about units is defined by a set of formulas, from which result units are determined, when arithmetic operations are performed on physical values.
This set of default formulas can be retrieved via "PhysicalUnit formulaStrings
".
Notice: we have included those formulas in the framework, so no internet access is required for these operations. Otherwise, operation in isolated networks (test labs) would be made impossible.
You can add more knowledge by:
Physic::PhysicalUnit addFormula: formulaString
As a concrete example, the Momentum (which is Energy * Time) is predefined via:
PhysicalUnit addFormula:'Momentum = Energy * Time'
the names in the formula must correspond to the unit names; if new units are to be made well known, it must be defined via:
Physic::PhysicalUnit addKnownUnit:aUnit
or
Physic::PhysicalUnit addKnownUnit:aUnit as:nameInFormula
Nature Constants[Bearbeiten]
The following constants (see [2]) are known to the parser and can be used in formula/equations. They can also be accessed by elementary code via the global variable "Physic::NatureConstants
" by index messages (i.e. "at:name" , "[name]" or simply name).
The values have been taken from public available data (such as Wikipedia). Some of them are measured or estimated values, which might have changed slightly by the time you read this (see below on how to update the facts database).
Fundamental Constants[Bearbeiten]
BoltzmannConstant => 1.380649e-23 J/K AvogadroConstant => 02214076e+23 1/mol ElectronCharge => -1.602176634e-19 C ElectronVolt => 1.602176634e-19 J PlanckConstant => 6.62607015e-34 Js PlanckTime => 5.391247e-44 s PlanckMass => 21.76434 µg PlanckLength => 1.616255e-35 m LightSpeed => 299792.458 km/s SoundSpeed => 343 m/s GravitationalConstant => 6.6743e-11 m³/(kg·s²) CoulombConstant => 8987551782 kg·m³/(s²·C²) VacuumPermittivity => 8.8541878188e-12 s⁴·A²/(m³·kg) VacuumPermeability => 1.25663706212e-06 H/m MolarGasConstant => 8.31446261815324 J/(mol·K)
or by their aliases:
LightSpeed c PlanckConstant h , ℎ (#8462) ReducedPlanckConstant hbar, ℏ (#8463) GravitationalConstant G VacuumPermittivity ε0 , epsilon_0 VacuumPermeability μ0 , mu_0 ElectronCharge e
For example:
Physic::NatureConstants at:'GravitationalConstant' => 6.6743e-11 m³/(kg·s²) Physic::NatureConstants['GravitationalConstant'] => 6.6743e-11 m³/(kg·s²) Physic::NatureConstants GravitationalConstant => 6.6743e-11 m³/(kg·s²) Physic::NatureConstants G => 6.6743e-11 m³/(kg·s²)
or:
Physic::NatureConstants at:'LightSpeed' => 299792.458 km/s Physic::NatureConstants ElectronCharge => -1.602176634e-19 C Physic::NatureConstants e => -1.602176634e-19 C
Elements[Bearbeiten]
atom => database with facts about atoms atom[X], for X in {'H','He','Na','Li','C','N','O','Au',...}.
provides data for 'name', 'symbol', 'atomNr', 'atomWeight', 'meltingTemperature', 'boilingTemperature', 'protons', 'neutrons', 'density', etc.
For example:
Physic::NatureConstants['atom'] => dictionary indexed by atom symbol Physic::NatureConstants['atom']['H'] => {"name":"Hydrogen","symbol":"H","atomNr":1,"atomWeight":...} dictionary of attributes of hydrogen Physic::NatureConstants['atom']['He']['atomWeight'] => 4.002602 amu (atomWeight of helium) Physic::NatureConstants['atom']['Li']['density'] => 534.0 kg/m³ (density of lithium) Physic::NatureConstants['atom']['Cu']['specificResistance'] => 1.68e-08 Ω/m (specific electric resistency of copper)
spoiler: access via messages is also possible:
carbon := Physic::NatureConstants['atom']['C']. carbon atomWeight => 12 amu Physic::NatureConstants atom Cu specificResistance => 1.68e-08 Ω/m (specific electric resistency of copper)
The builtin database is incomplete; you may want to fill in missing data in an initialization action, as described below. To see the information as present in your system, evaluate (in a workspace):
(Physic::NatureConstants['atom']) inspect
.
and fill in values with:
Physic::NatureConstants['atom']['Cu']['soundSpeed'] := 3570 meter / 1 seconds
.
Astronomic Data[Bearbeiten]
astronomicalObjects[X], for X in {'earth', 'moon', 'sun', 'mercury', 'venus', 'mars', 'jupiter', 'saturn', 'neptune', 'uranus', 'pluto' }
'planets' is an alias. Both provide planetary data: mass, radiusMean, volume, aphelion, perihelion, escapeVelocity.
For example, Physic::NatureConstants['planets']['venus']['mass']
.
Physic::NatureConstants['astronomicalObjects'] => dictionary indexed by name Physic::NatureConstants['astronomicalObjects']['mars'] => dictionary of attributes of mars Physic::NatureConstants['astronomicalObjects']['venus']['mass'] => mass of venus
other useful constants are:
DISTANCE_SUN_EARTH DISTANCE_EARTH_MOON AstronomicalUnit EarthGravity earth, moon, sun, mercury, venus, mars, jupiter, saturn, uranus, neptune, pluto mass[X], for X in planet-names volume[X], for X in planet-names radius[X], for X in planet-names
Physic::NatureConstants['planets']['earth']['mass'] Physic::NatureConstants['planets']['earth']['massWater'] Physic::NatureConstants['planets']['earth']['massAtmosphere'] Physic::NatureConstants['planets']['earth']['surface'] Physic::NatureConstants['planets']['earth']['surfaceLand'] Physic::NatureConstants['planets']['earth']['surfaceWater']
Examples:
Physic::NatureConstants['planets']['sun']['mass'] => 1.9885e+30 kg Physic::NatureConstants['planets']['sun']['volume'] => 1.41e+18 km³ Physic::NatureConstants['planets']['earth']['mass'] => 108.321 km³
Filling the Facts Database[Bearbeiten]
The database as deployed obviously cannot provide any possible useful value for your particular application. The current set is provided for examples and only contains knowledge which is often used in physics, some chemistry and mechanical applications.
If you expect more builtin data, please let us know. If you find inexact values or wrong values due to typing errors, or if new scientific research data is available, also.
In any case, you can fill or fix the database yourself with both missing, inexact or wrong values:
Physic::NatureConstants constants[name] := newValue
or (the equivalent):
Physic::NatureConstants constants at:name put:newValue
For example, to add data for an atom, you could write:
goldInfo := Physic::NatureConstants['atom']['AU']. goldInfo['meltingTemperature'] := 1337.33 kelvin.
You can also add completely new domain specific data. For example, if your machines process wood and the densities are required in your drilling setup, you may want to execute:
woodData := Dictionary forCaseInsensitiveKeys. woodData['walnut'] := { density: 650 kiloGram / 1 cubicMeter }. woodData['mahogany'] := { density: 600 kiloGram / 1 cubicMeter }. woodData['maple'] := { density: 700 kiloGram / 1 cubicMeter }. woodData['oak'] := { density: 770 kiloGram / 1 cubicMeter }. woodData['rosewood'] := { density: 840 kiloGram / 1 cubicMeter }. woodData['cherry'] := { density: 7400 kiloGram / 1 cubicMeter }. woodData['balsa'] := { density: 120 kiloGram / 1 cubicMeter }. Physic::NatureConstants['wood'] := woodData.
then use in your code:
Physic::NatureConstants['wood']['çherry']['density']
Notice that these numbers are just examples; the actual densities vary much and also depend on dryness and other factors.
Examples Involving Constants[Bearbeiten]
In Smalltalk (accessing the constants directly):
Physic::NatureConstants['speed']['sound'] Physic::NatureConstants['planets']['venus'] Physic::NatureConstants['planets']['mars']['mass'] 1.0 kiloGram * (Physic::NatureConstants['LightSpeed']) squared => 89875.51 TJ
In JavaScript:
Physic::NatureConstants['speed']['sound']
In Smalltalk (using the Math language parser):
Physic::Parser evaluate:'1 kg * LightSpeedˆ2'. Physic::Parser evaluate:'1 kg * LightSpeed²' Physic::Parser evaluate:'mass[sun] * mass[earth] / earth[perihelion]ˆ2'.
In Math language:
1 kg * LightSpeedˆ2 GraviationalConstant * mass[sun] * mass[earth] / earth[perihelion]²
Measured Physical Values[Bearbeiten]
You can combine physical values and measurement values to keep track of errors in computations.
Example:
Assuming, that your cheap 10% accurate voltmeter measured 10 volts, this could be written as:
u := (10 volt ±% 10).
and if that voltage was measured across a cheap 100 ohm resistor with 5% precision,
r := (100.0 ohm ±% 5).
the current will be:
i := u / r.
which is:
(MeasurementValue value:100.0 minValue:85.7 maxValue:115.8) mA
and its min/max/expected values can be extracted with:
i minValue => 84.7 mA i maxValue => 115.8 mA i expectedValue => 100 mA i relativeError => 0.15
or nicer:
i minValue asMilliAmperes roundedToScale:2 => 84.71 mA i maxValue asMilliAmperes roundedToScale:2 => 115.79 mA i expectedValue asMilliAmperes roundedToScale:2 => 100 mA
Notice: currently, you cannot take the plain minValue/maxValue and round them, as these are kept in baseUnits internally, which would round to 1/100 ampere instead of 1/100 milliampere. Therefore, the values are first forced into milliAmperes so that the rounding is what we want.
Physical Values and Numeric Precision[Bearbeiten]
Physical values will use the underlying number type when computing new values. For example,
10 volt / 3 ampere => (10/3) ohm
generates a fractional Ohm value *whis is exact), whereas:
10.0 volt / 3 ampere => 3.33333 ohm
returns a float value (which is an approximation).
It is usually a good idea to start with float values, and scale to the desired precision output when printing. Typically floats are used in the engineering domains, where measurements with error tolerances are involved. If your measurement and components have an error in the percent range, there is no need to compute exact or with a precision in the 10e-50 range.
Please refer to the "Numeric Limits" document for more details on number types.
Printing Physical Values[Bearbeiten]
The printing of the amount depends on the underlying number representation. As shown previously, this can be a Fraction, a Float, an Integer or any other number subtype, depending on the values from which it was computed/constructed.
For convenient printing, fractions are usually not wanted; you can either convert the amount to a scaledDecimal when creating the value, or convert the value afterwards. ScaledDecimals print the value rounded to a given number of digits, but use the full internal precision for computations.
For example:
(1/3) printString => '(1/3)' (1/3) asFloat printString => '0.333333333333333' ((1/3) asScaledDecimal:2) printString => '0.33' ((1/3) asFixedDecimal:2) printString => '0.33'
(2/3) printString => '(2/3)' (2/3) asFloat printString => '0.666666666666667' ((2/3) asScaledDecimal:2) printString => '0.67' ((2/3) asFixedDecimal:2) printString => '0.67'
However:
((1/3) + (1/3)) printString => '(2/3)' ((1/3) asFloat + (1/3) asFloat) printString => '0.666666666666667' ( ((1/3) asScaledDecimal:2) + ((1/3) asScaledDecimal:2)) printString => '0.67' ( ((1/3) asFixedDecimal:2) + ((1/3) asFixedDecimal:2)) printString => '0.66'
Notice the difference between scaledDecimals (which compute exact values), and fixedDecimals (which compute with the printed values). Only use fixedDecimals for monetary tables, where the sums of the printed numbers should sum up correctly.
So, to print a length value of 15mm, the following can be used:
15 milliMeter => 15 mm 15 milliMeter as:'Meter' => (3/200) m 15 milliMeter as:'m' => (3/200) m 15.0 milliMeter as:'m' => 0.015 m 15.0 milliMeter as:'cm' => 1.5 cm
(15 milliMeter as:'m') asScaledDecimal:1 => 0.0 m (15 milliMeter as:'m') asScaledDecimal:2 => 0.02 m (15 milliMeter as:'m') asScaledDecimal:3 => 0.015 m (15 milliMeter as:'m') asScaledDecimal:4 => 0.0150 m
(15 milliMeter as:'cm') asScaledDecimal:1 => 1.5 cm (15 milliMeter as:'cm') asScaledDecimal:2 => 1.50 cm (15 milliMeter as:'cm') asScaledDecimal:3 => 1.500 cm (15 milliMeter as:'cm') asScaledDecimal:4 => 1.5000 cm
(15 milliMeter as:'in') asScaledDecimal:1 => 0.6 in (15 milliMeter as:'in') asScaledDecimal:2 => 0.59 in (15 milliMeter as:'in') asScaledDecimal:3 => 0.591 in (15 milliMeter as:'in') asScaledDecimal:4 => 0.5906 in
Physical Values in Activity Diagrams[Bearbeiten]
Unfortunately, the arithmetic actions in the standard library were defined with pin types being "Number
", instead of the more general "ArithmeticValue
" (of which PhysicalValues inherit). Thus, they will not accept physical values if type checking is enabled on the pin values (although the underlying primitive code would handle those types).
We therefore provide a separate PhysicalValues library, with redefined arithmetic actions. Please use those when dealing with physical values (instead of "forcing" types or disabling type checks).
Late note: these actions are now found in the standard library under the "Arithmetic/More Arithmetic" category.
Freeze values can be given either using the above listed instance creation messages on number (e.g. "10 meters
" or "1 kilo joule
") or by using a unit suffix, possibly with an appreviated SI prefix, as in "10 kV
" or "10 mA
".
Physical Values as Freeze Value[Bearbeiten]
Pins of type "PhysicalValue" accept numeric values followed by a unit symbol, such as "1 kg
" or "1 fl oz
", "10 N
" or "10 newton
".
Physical Values in Elementary Code[Bearbeiten]
See examples below.
Math Language Workspace[Bearbeiten]
You can switch the workspace (Notepad) window to accept math language syntax (instead of Smalltalk or JavaScript).
For this, open a Notepad via "Extras" → "Tools" → "Notepad'", and choose "Math/Physic" in its "Workspace" menu1).
You can now enter math language expressions, such as:
x := 5 sin(xˆ2 + 3) => 0.270905788307869
or
deriv ( sin(xˆ2 + 5x), x ) => (2·x + 5)·cos(x² + 5·x)
and evaluate them (select the text, possibly multiple lines) and click on the "PrintIt" icon or select "PrintIt" from the right-button menu. The result of the evaluation will be pasted and selected into the window, so by pressing Delete or Backspace or CTRL-x, it can be removed quickly.
1) Make sure that "Autodefine as Workspace Variable" is checked in the workspace's "Workspace" → "Autodefine Variables" menu.
Otherwise assigned variables such as "x" above will only be known within one doIt.
Examples[Bearbeiten]
The following code snippets are plain Smalltalk code + the printed representation (as for example found in a report).
For JavaScript, write "n.X()" instead of "n X"
(eg. "1.kiloGram() + 10.0.gram()
" instead of "1 kiloGram + 10.0 gram
").
The following shows the printed output of typical Smalltalk expressions. Notice again, that by default, the units present themself as metric SI units (eg. "1 meter" will print as meters). To force them to print as imperial or us units, use the "asXXX" message (eg. "1 meter asFeet").
Length Examples:[Bearbeiten]
(1/4) inches | => | 6.35 mm |
(1/4) inches asInches | => | 0.25 in |
10 milliMeter | => | 10 mm |
10 milliMeter asInches | => | 0.3937 in |
10 milliMeter as:'in' | => | 0.3937 in |
10 milliMeter as:'ft' | => | 0.032808 ft |
10 milli meter asInches | => | 0.3937 in |
10 feet | => | 3.048 m |
1.8 meter asFeet | => | 5.905 ft |
10 miles | => | 16.09 km |
10 nauticalMiles | => | 18.52 km |
1 parsec | => | 3.261563777 ly |
10 kiloMeters asMeters | => | 10000 m |
1 astronomicalUnits asMiles rounded | => | 92955807 mi |
1 lightYears asAstronomicalUnits rounded | => | 63241 au |
1000 lightYears as:(Physic::Length parsec) | => | 306.6014 pc |
1 micro inch | => | 25.4 nm |
1.80 meter asFeetAndInches | => | 5′10.866 |
1 yards | => | 0.9144 m |
e'He is {(5 foot+2 inches) asFeetAndInchesRounded}...' (1) | => | 'He is 5′2″...' |
e'He is {(5 foot+2 inches)}...' | => | 'He is 1.5748 m...' |
10 centi meter | => | 0.1 m (prints as m) |
10 centiMeter | => | 0.1 m (prints as m) |
Physic::PhysicalUnit centimeter unitAmount:10 | => | 10 cm (prints as cm) |
1)The e'...' is a Smalltalk string with embedded expressions.
Velocity Examples[Bearbeiten]
100 miles / 1 hours | => | 44.704 m/s |
(100 miles / 1 hours) as:'mph' | => | 100 mph |
100 kiloMeterPerHour as:'mph' | => | 62.137119 mph |
100 milesPerHour asKiloMetersPerHour | => | 160.9344 km/h |
1 milliMeter / 1 days | => | 11.574 nm/s |
(186282 miles+698 yard+2 feet+5 inches+(21 / 127) inches) / 1 seconds | => | 299792.458 km/s |
Mass Examples:[Bearbeiten]
1 kiloGram + 10.0 gram | => | 1.01 kg |
(1 kiloGram + 10 gram) asGrams | => | 1010 g |
10 gram | => | 10 g |
10 gram asKiloGrams | => | (1/100) kg |
10.0 gram asKiloGrams | => | 0.01 kg |
10 gram asMilliGrams | => | 10000 mg |
1 microGram | => | 1 µg |
1 micro gram | => | 1 µg |
10000 gram | => | 10 kg |
1 pound | => | 453.59237 g |
1 pound asKiloGrams | => | 0.45359237 kg |
1 pound asPounds | => | 1.0 lb |
1 kiloGram asPounds | => | 2.20462262184878 lb |
1 atomicMassUnits asKiloGrams | => | 1.66053906892e-27 kg |
Temperature Examples:[Bearbeiten]
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 |
100 rankine asRankine | => | 100.0 °R |
Energy Examples:[Bearbeiten]
1 joule asElectronVolts | => | 6.24150912550149E+18 eV |
1 joule asCalories | => | 0.239005736137667 cal |
1 joule asBTUs | => | 0.000947817 BTU |
1.0 joule asKiloWattHours | => | 2.77777777777778E-07 kWh |
10 electronVolts | => | 1.6021766208E-18 J |
1 mega electronVolts asJoules | => | 1.602176634E-13 J |
1000 joule asKiloWattHours | => | 0.000278 kWh |
1000.0 kiloJoule asKiloWattHours | => | 0.2778 kWh |
c := Physic::NatureConstants lightspeed | => | 299792.458 km/s |
1 kg * c squared | => | 89875.518 TJ (E = mc²) |
(1.0 kg * c squared) asGigaWattHours | => | 24965.42 GWh (get me some antimatter) |
1 electronVolts | => | 1.602176634e-19 J (see wikipedia) |
1 electronVolts / Physic::NatureConstants c squared | => | 1.7826619216279e-36 kg (mass) |
1 electronVolts / Physic::NatureConstants c | => | 5.34428599267831e-28 kg·m/s (momentum) |
1 electronVolts / Physic::NatureConstants boltzmannConstant | => | 11604.5181215501 K (temperature) |
Physic::NatureConstants hbar / 1 electronVolts | => | 6.58211956950907e-16 s (time) |
Physic::NatureConstants hbar * Physic::NatureConstants c / 1 electronVolts | => | 197.326980459302 nm (distance) |
Power Examples:[Bearbeiten]
1 kilo watt | => | 1000 W |
1 imperial hp | => | 745.699871 W |
1 metric hp | => | 735.49875 W |
5 volt * 10 ampere | => | 50 W |
1 mega watt | => | 1000 kW |
70 giga watt * 10 hours | => | 2520 TJ |
Electricity Examples:[Bearbeiten]
1 coulomb asAmpereHours | => | 0.000277 Ah |
1.1 volt / 10 kilo ohm | => | 110.0 µA |
100 micro farad * 10.0 volt | => | 0.001 C |
100 ohm * 0.1 micro farad | => | 10.0 µs |
20 milli ampere * 10 seconds | => | (1/5) C |
20.0 milli ampere * 10 seconds | => | 0.2 C |
(Physic::Voltage dBu unitAmount:4) asVolts | => | 1.2277 V |
'1 / (2π × √(1 farad × 1 henry))' asPhysicExpression value | => | 0.1591 Hz (from formula) |
1 / (2 * Float pi * (1 farad * 1 henry) sqrt) | => | 0.1591 Hz (as Smalltalk code) |
1 / (1 microFarad * 2 kiloOhm) | => | 500 Hz |
100 ohm | 50.0 ohm | => | 33.33 Ω (two resistors in parallel) |
Physic::ElectricResistance' colorCode:#(yellow violet red) | => | 4700 Ω |
Volume Examples:[Bearbeiten]
1000 liter | => | 1 m³ |
1000 liter asLiters | => | 1000 l |
1000 liter asHectoLiters | => | 10 hl |
1000 liter asCubicInches | => | 61023.744095 cuin |
100.0 liter asCubicInches | => | 6102.3744095 cuin |
100.0 deci liter asCubicInches | => | 610.23744095 cuin |
1 liter asCubicInches | => | 61.023744095 cuin |
1 deci liter asCubicInches | => | 6.1023744095 cuin |
1 milli liter asCubicInches | => | 0.061023744095 cuin |
1 flozGB | => | 28.4130625 ml |
1 flozUS | => | 29.5735296 ml |
1 flozGB asFlozUS | => | 0.960759940 US fl oz |
1 flozUS asFlozGB | => | 1.040842731 imp fl oz |
1 flozGB asScaledDecimal:2 | => | 28.41 ml |
1 inch cubed | => | 16.387064 ml |
1 inch cubed asLiters | => | 0.016387064 l |
1 inch cubed asCubicInches | => | 1.0 cuin |
1 inch cubed asCubicInches unitString | => | 'cuin' |
1 inch cubed asCubicInches unitAmount | => | 1.0 |
1 inch cubed asCubicInches unitStringSI | => | 'm³' |
1 inch cubed asCubicInches amount | => | 1.6387064E-05 |
Volume barrels unitAmount:1 | => | 1 bbl. |
(Volume barrels unitAmount:1) asGallonsUS | => | 42.0 US gal |
(Volume barrels unitAmount:1) asLiters | => | 158.987295 l |
Volume barrelsIMP unitAmount:1 | => | 1 bbl. Imp |
(Volume barrelsIMP unitAmount:1) asLiters | => | 159.1131599 l |
Angle Examples:[Bearbeiten]
10 degrees | => | 0.174533 rad |
0.2 radians | => | 0.2 rad |
180 degrees | => | 3.14159265358979 rad |
180 degrees asDegrees | => | 180.0 ° |
180 degrees asDegrees asRadians | => | 3.14159265358979 rad |
90 degrees asGon | => | 100 gon |
gonUnit := (Physic::PhysicalUnit angle gon) | => | Gon (the unit, not a value) |
gonUnit unitAmount:100 | => | 100 gon |
(gonUnit unitAmount:100) asDegrees | => | 90 ° |
(270 degrees + 91 degrees) = 361 degrees | => | true |
Force Examples:[Bearbeiten]
10 newton | => | 10 N |
1 newton asGramForce | => | 101.97 gf |
(Physic::Force gramForce unitAmount:50) | => | 50 gf |
(Physic::Force gramForce unitAmount:50) asNewton | => | 0.4903325 N |
(Physic::Force gramForce unitAmount:50) as:'N' | => | 0.4903325 N |
(Physic::Force dyne kiloUnit unitAmount:1) as:'N' | => | 0.01 N |
(Physic::Force kilo dyne unitAmount:1) as:'N' | => | 0.01 N |
Pressure Examples:[Bearbeiten]
1 kilo pascal | => | 1000 Pa |
1.5 kilo pascal asTorr | => | 11.25 Torr |
(Physic::Pressure torr unitAmount:11.5) asPascal | => | 1533.207 Pa |
(Physic::Pressure torr unitAmount:11.5) as:'Pa' | => | 1533.207 Pa |
((Physic::PhysicalUnit unitWithUnitString:'lbf/in²') unitAmount: 0.01933678) as:'Pa' | => | 133.322404931392 Pa |
((Physic::PhysicalUnit unitWithUnitString:'lbf/in²') unitAmount: 0.01933678) as:'mmHg' | => | 1.00000013138373 mmHg |
Bytes Examples:[Bearbeiten]
1 kilo byte | => | 1000 byte |
1 kibi byte | => | 1024 byte |
100 kilo byte asKibiBytes rounded | => | 98 kiB |
1 kilo byte / 1 seconds | => | 1000 B/s |
1 kilo byte / 1 seconds * 5 minutes | => | 300 kB |
1 mega bits / 2 seconds | => | 500000 b/s |
Misc Other Examples:[Bearbeiten]
10 candela / 1 square meter | => | 10 lx |
Other (Fun) Examples:[Bearbeiten]
Planet Distance[Bearbeiten]
what is the smallest possible distance between earth and mars
(See also: google for "smallest distance earth mars"):
|earth mars minDistMarsSun maxDistEarthSun| earth := Physic::NatureConstants['planets']['earth']. mars := Physic::NatureConstants['planets']['mars']. minDistMarsSun := mars['perihelion']. "/ See: "Orbit of Mars" "/ perihelion is the smallest distance from the sun maxDistEarthSun := earth['aphelion']. "/ See: "Orbit of Earth" "/ aphelion is the largest distance from the sun minDistMarsSun - maxDistEarthSun => 54600000km (54.6 mio km)
Electric Force / Coulomb's Law[Bearbeiten]
the force between two electrons at 1m distance:
q := Physic::NatureConstants['ElementaryCharge']. "/ is: 1.60217663 × 10-19 C k := Physic::NatureConstants['CoulombConstant']. "/ is: 8987551792.3 kg·m³/(s²·C²) r := 1 meter. f := k * q squared / r squared. => 2.31e-28 N
References[Bearbeiten]
International System of Units (SI)
US Customary Units
CGS System
Avoirdupois
Troy Weight
Imperial Units