The library contains type definitions for several kind of units. They are defined as asbtract types to simplify their usage as much as possible.
(10 : Millimetre) * 100 == (1 : Metre);
// other example
var f = (27 : Celsius).toFahrenheit()
The following units are currently supported:
- amount of substance:
Mole
,PoundMole
. - angle:
BinaryDegree
,Degree
,Grad
,HourAngle
,MinuteOfArc
,Point
,Quadrant
,Radian
,Revolution
,SecondOfArc
,Sextant
,Turn
. - current:
Ampere
. - digital:
Byte
,Exabit
,Exabyte
,Gigabit
,Gigabyte
,Kilobit
,Kilobyte
,Megabit
,Megabyte
,Petabit
,Petabyte
,Terabit
,Terabyte
,Yottabit
,Yottabyte
,Zettabit
,Zettabyte
. - length:
AstronomicalUnit
,Centimeter
,Centimetre
,Chain
,EarthRadius
,Fathom
,Foot
,Furlong
,Inch
,Kilometer
,Kilometre
,League
,LightYear
,Line
,Meter
,Metre
,Micrometer
,Micrometre
,Mile
,Millimeter
,Millimetre
,Nanometer
,Nanometre
,NauticalMile
,Thou
,Yard
. - luminous intensity:
Candela
,Candlepower
. - mass:
Centigram
,Dalton
,Drachm
,Grain
,Gram
,Hundredweight
,Kilogram
,Megagram
,Microgram
,Milligram
,Nanogram
,Ounce
,Picogram
,PlankMass
,Pound
,Quarter
,Slug
,SolarMass
,Stone
,Ton
,Tonne
,UnifiedAtomicMassUnit
. - temperature:
Celsius
,Centrigrade
,Delisle
,Fahrenheit
,Kelvin
,Newton
,Rankine
,Reaumur
,Romer
. - time:
Centriday
,Day
,Fortnight
,Fourth
,Gigasecond
,Hour
,JiffyPhysics
,JulianYear
,Ke
,Kilosecond
,Megasecond
,Microsecond
,Millisecond
,Minute
,Nanosecond
,Picosecond
,PlankTimeUnit
,Second
,Shake
,Svedberg
,SynodicMonth
,Terasecond
,Third
,TropicalMonth
,Week
.
For now the library essentially helps with conversions and math operations. At some point derivative units might be introduced to make things more interesting.
Also notice that the types are automatically generated. If you want to contribute to the library make sure to make changes in the definitions. The code is generated using this generator.
The library has not been exhaustively tested, please pay attention to the correctness of the results you get.
Important. This library should be used with the knowledge that converting values and perform some operations on the values might result in loss of precision. The limitation come from the fact that the underlying type is Float
. Converting LightYear
s to Millimitre
s might not work as well as you expect!
From the command line just type:
haxelib install thx.unit
To use the dev
version do:
haxelib git thx.core https://github.com/fponticelli/thx.unit.git