Defining units

SpeQ has all common units built-in, as listed here. However, if there is a specific unit missing, you can define this unit by yourself. To create a unit, you can use the function AddUnit. This function has the syntax
AddUnit(name {, relation {, prefixtype})
To create a new base unit you can use:
       Unit Euro created
To add a unit with a relation to another unit, you can specify the relation:
AddUnit(Dollar, 0.73 Euro)
       Unit Dollar created
To enable prefixes like kilo, mega, or giga, one can specify the prefixtype PrefixName. For prefixes like K, M, G, you can use the prefixtype PrefixAbbr. If you want to do someting with binary prefixes (with powers of 1024 instead of 1000), you can use prefixtype PrefixNameBinary or PrefixAbbrBinary.
AddUnit(barn, 1e-28 m, PrefixName)
       Unit barn created

325 millibarn + 5.2 barn
       Ans = 5.525 barn
Back to top


The following functions are available for creating and deleting units.
Function Description
AddUnit(name {, relation
{, prefixtype})
Add a new, custom unit with given name. One can optionally provide a relation with an other unit. To enable prefixes, you can choose the values PrefixNone (default), PrefixAbbr, PrefixName, PrefixAbbrBinary, or PrefixNameBinary.

Clear(unitname) Delete a custom unit.

Back to top


'Examples on defining custom units

' Add currency units
' (check internet for actual currency rates)
       Unit euro created
AddUnit(dollar, 0.73 euro)
       Unit dollar created

' Convert currency
Convert(5 euro, dollar)
       Ans = 6.849315068 dollar

' By default, the units do not support prefixes
' like K, M, G, or kilo, mega, giga, etc.
' you can enable usage of these prefixes by 
' specifying the prefixtype. You can choose 
' PrefixNone (default), PrefixAbbr, PrefixName,
' PrefixAbbrBinary, or PrefixNameBinary.
AddUnit(barn, 1e-28 m^2, PrefixName)
       Unit barn created
325 millibarn + 5.2 barn
       Ans = 5.525 barn

' You can use the prefixtypes PrefixAbbrBinary
'  and PrefixNameBinary for digitally computing.
AddUnit(MyByte, PrefixNameBinary)
       Unit MyByte created
1024 MyByte
       Ans = 1 kibiMyByte

' Create another unit
AddUnit(kilometer_per_hour, 1 km/h)
       Unit kilometer_per_hour created
5 kilometer_per_hour * 2.5 hours
       Ans = 12.5 km
'delete the unit
Back to top

See Also

Defining variables, Functionstree, Units, Units Overview, Wikipedia