PhysicalValues/en: Unterschied zwischen den Versionen

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen
Zeile 134: Zeile 134:
*''aLength'' '''asYards''' <br>Enforces explicit printing in yards.
*''aLength'' '''asYards''' <br>Enforces explicit printing in yards.


*''aLength'' '''asFeetAndInches''' <br>Enforces explicit printing in feet and inches.
*''aLength'' '''asFeetAndInches''' <br>Enforces explicit printing in feet and inches (in rounded to 4 digits).


=== Temperature ===
=== Temperature ===

Version vom 25. Oktober 2019, 16:14 Uhr

Expecco supports values with units to represent physical values such as length, acceleration, area, volume, mass, temperature etc.

Physical values are useful for a nicer presentation of values (eg. in a report) and to convert between unit systems (eg. metric vs. imperial vs. US).

Physical values are implemented by the underlying Smalltalk system and can be used in JavaScript and Smalltalk elementary blocks. Similar public domain packages are available for Node and Python actions - these have to be installed with "rpm"or "pip".

Base Units[Bearbeiten]

All base units are measured in their corresponding SI standard units and print with an appropriate scaling prefix.

For example, a mass, which has a base unit of kilogram ("kg") will print itself as "kg', 'mg', 'µg' etc. depending on its magnitude. Explicit converters can be used to enforce a particular unit printing (eg. if you insist on printing a mass in pounds, in grams, etc.). See examples below on how those converters affect the printout of a value.

Base units are:

s	second	    time
m	metre	    length
kg	kilogram    mass
A	ampere	    electric current
K	kelvin	    temperature
mol	mole	    amount of substance
cd	candela	    luminous intensity

Derived Units[Bearbeiten]

Additional derived units are:

V      volt                voltage
Hz     hertz               frequency
m/s    meter per second    speed, velocity
m/s²   m/s per second      acceleration
m²     square meter        area
m³     cubic meter         volume
pa     pascal              pressure
w      watt                power
N      newton              force
J      joule               energy
Ω      ohm                 electric resistance
C      coulomb             electric charge

SI Prefix[Bearbeiten]

Numbers can be scaled by an SI prefix message. For example, without si prefix:

1 gram -> '1 g'

whereas with a 'micro' prefix:

1 micro gram -> '1 µg'

and:

1 hecto liter -> '100 liter'

Possible scaling prefixes are:

yocto   1E-24   1 / 1000000000000000000000000 
zepto   1E-21   1 / 1000000000000000000000 
atto    1E-18   1 / 1000000000000000000
femto   1E-15   1 / 1000000000000000
pico    1E-12   1 / 1000000000000
nano    1E-9    1 / 1000000000
micro   1E-6    1 / 1000000
milli   1E-3    1 / 1000
centi   1E-2    1 / 100
deci    1E-1    1 / 10
deca    1E+1    10
hecto   1E+2    100
kilo    1E+3    1000
mega    1E+6    1000000
giga    1E+9    1000000000
tera    1E+12   1000000000000
peta    1E+15   1000000000000000
exa     1E+18   1000000000000000000
zetta   1E+21   1000000000000000000000
yotta   1E+24   1000000000000000000000000

Mass[Bearbeiten]

Mass is measured in units of kilogram. The following operations return an instance of a mass (i.e. a value with a unit of "Mass"):

  • number kiloGram
    Generates a mass-value of n kilograms. Same as n kilo gram.
  • number gram
    Generates a mass-value of n grams.
  • number milliGram
    Generates a mass-value of n milligrams. Same as n milli gram.
  • number microGram
    Generates a mass-value of n micrograms. Same as n micro gram.
  • number pounds
    Generates a mass-value of n pounds. A pound is 453.59237 gram.

Conversion[Bearbeiten]

  • aMass asGrams
    Returns the original mass but enforces explicit printing in grams.
  • aMass asMilliGrams
    Enforces explicit printing in milligrams.
  • aMass asMicroGrams
    Enforces explicit printing in micrograms.
  • aMass asKiloGrams
    Enforces explicit printing in kilograms.
  • aMass asPounds
    Enforces explicit printing in pounds.

Length[Bearbeiten]

Length is measured in meters.

  • number meter
    Generates a length-value of n meters.
  • number centiMeter
    Generates a length-value of n centimeters. Same as n centi meter.
  • number milliMeter
    Generates a length-value of n millimeters. Same as n milli meter.
  • number microMeter
    Generates a length-value of n micrometers. Same as n micro meter.
  • number nanoMeter
    Generates a length-value of n nanometers. Same as n nano meter.
  • number kiloMeter
    Generates a length-value of n kilometers. Same as n kilo meter.
  • number inch
    Generates a length-value of n inches. An inch is 25.4 mm.
  • number feet
    Generates a length-value of n feet. A foot is 0.3048 m.
  • number landMiles
    Generates a length-value of n landMiles. A landMile is 5280 feet or 1609.344 m.
  • number nauticalMiles
    Generates a length-value of n nauticalMiles. A nauticalMile is 1852 m.

Conversion[Bearbeiten]

  • aLength asMeters
    Returns the original length but enforces explicit printing in meters.
  • aLength asMilliMeters
    Enforces explicit printing in millimeters.
  • aLength asMicroMeters
    Enforces explicit printing in micrometers.
  • aLength asKiloMeters
    Enforces explicit printing in kilometers.
  • aLength asInches
    Enforces explicit printing in inches.
  • aLength asFeet
    Enforces explicit printing in feet.
  • aLength asYards
    Enforces explicit printing in yards.
  • aLength asFeetAndInches
    Enforces explicit printing in feet and inches (in rounded to 4 digits).

Temperature[Bearbeiten]

  • number kelvin
    Generates an temperature-value of n Kelvin.
  • number degreesCelcius
    Generates an temperature-value of n degrees Celsius.
  • number degreesFahrenheit
    Generates an temperature-value of n degrees Fahrenheit.

Frequency[Bearbeiten]

  • number hertz
    Generates an frequency-value of n hertz.
  • number kiloHertz
    Generates an frequency-value of n kilohertz.
  • number megaHertz
    Generates an frequency-value of n megahertz.
  • number gigaHertz
    Generates an frequency-value of n gigahertz.

Energy[Bearbeiten]

  • number joule
    Generates an energy-value of n joule.
  • number kiloJoule
    Generates an energy-value of n kilojoule.
  • number megaJoule
    Generates an energy-value of n megajoule.
  • number kiloWattHours
    Generates an energy-value of n kiloWattHours.

Power[Bearbeiten]

  • number watt
    Generates a power-value of n watt.
  • number kiloWatt
    Generates a power-value of n kiloWatt.
  • number megaWatt
    Generates a power-value of n megaWatt.
  • number gigaWatt
    Generates a power-value of n gigaWatt.

Area[Bearbeiten]

  • number squareMeter
    Generates an area-value of n square meters.
  • number hectare
    Generates an area-value of n hectares.

Volume[Bearbeiten]

  • number liter
    Generates an volume-value of n liters.
  • number milliLiter
    Generates a length-value of n milliliters.

Mass Density[Bearbeiten]

This is a derived unit, which is generated when dividing a mass by a volume; eg:

10 kiloGram / 1 liter 

gives

'10000 kg / m³'

Examples[Bearbeiten]

Smalltalk code + printed representation.

1 kiloGram + 10.0 gram -> '1.01 kg' 
10 gram -> '10 g'
10 gram asKiloGrams -> '0.01 kg'
10 gram asMilliGrams -> '10000 mg'
1 microGram -> '1 µg'
1 micro gram -> '1 µg'
1 pound -> '453.59237 g'
1 pound asKiloGrams -> '0.45359237 kg'
1 pound asPounds -> '1.0 lb' 
1 kiloGram asPounds -> '2.20462262184878 lb'
1 micro inch -> '25.4 nm'



Copyright © 2014-2024 eXept Software AG