Ampere (electric current) component of the unit dimension.
Candela (luminous intensity) component of the unit dimension.
Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Convert a scalar value from this unit to the given unit. If the units do not have the same dimension then throw Err. For example, to convert 3km to meters:
m := Unit("meter")
km := Unit("kilometer")
km.convertTo(3f, m) => 3000f
Return string format as specified by define.
Return the string format of the dimension portion of definition
Two units are equal if they have reference equality because all units are interned during definition.
Return toStr.hash
.
Kelvin (thermodynamic temperature) component of the unit dimension.
Kilogram (mass) component of the unit dimension.
Meter (length) component of the unit dimension.
Mole (amount of substance) component of the unit dimension.
Return the primary name identifier of this unit. This is always the first item in ids.
Return the offset factor used to convert this unit "from normal". See class header for normalization and conversion equations. Offset is used most commonly with temperature units. The offset for normalized unit is always zero.
Return the scale factor used to convert this unit "from normal". For example the scale factor for kilometer is 1000 because it is defined as a 1000 meters where meter is the normalized unit for length. See class header for normalization and conversion equations. The scale factor for the normalized unit is always one.
Second (time) component of the unit dimension.
Return the abbreviated symbol for this unit. This is always the last item in ids.
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
Return symbol.
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
defineDefine a new Unit definition in the VM's unit database using the following string format:
unit := <ids> [";" <dim> [";" <scale> [";" <offset>]]]
names := <ids> ("," <id>)*
id := <idChar>*
idChar := 'a'-'z' | 'A'-'Z' | '_' | '%' | '/' | any char > 128
dim := <ratio> ["*" <ratio>]* // no whitespace allowed
ratio := <base> <exp>
base := "kg" | "m" | "sec" | "K" | "A" | "mol" | "cd"
exp := <int>
scale := <float>
offset := <float>
If the format is incorrect or any identifiers are already defined then throw an exception.
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
fromFind a unit by one of its identifiers if it has been defined in this VM. If the unit isn't defined yet and checked is false then return null, otherwise throw Err. Any units declared in "etc/sys/units.txt" are implicitly defined.
Optional
checked: booleanStatic
listStatic
makeStatic
quantitiesList the quantity names used to organize the unit database in "etc/sys/units.txt". Quantities are merely a convenient mechanism to organize the unit database - there is no guarantee that they include all current VM definitions.
Static
quantity
Unit models a unit of measurement. Units are represented as:
A unit identifier is limited to the following characters:
a
-z
andA
-Z
_
/
%
$
Units with equal dimensions are considered to measure the same physical quantity. This is not always true, but good enough for practice. Conversions with the
convertTo
method are expressed with the following equations:As a simple, pragmatic solution for modeling Units, there are some units which don't fit this model including logarithm and angular units. Units which don't cleanly fit this model should be represented as dimensionless (all ratios set to zero).
Fantom's model for units of measurement and the unit database are derived from the OASIS oBIX specification.