forked from fponticelli/thx.unit
/
Drachm.hx
88 lines (80 loc) · 3.41 KB
/
Drachm.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package thx.unit.mass;
import thx.core.Floats;
// TODO parse string
abstract Drachm(Float) {
@:from inline static public function floatToDrachm(value : Float) : Drachm
return new Drachm(value);
function new(value : Float)
this = value;
@:op( -A ) inline public function negate() : Drachm
return -this;
@:op( A+B) inline public function add(other : Drachm) : Drachm
return this + other.toFloat();
@:op( A-B) inline public function subtract(other : Drachm) : Drachm
return this - other.toFloat();
@:op( A*B) inline public function multiply(other : Float) : Drachm
return this * other;
@:op( A/B) inline public function divide(other : Float) : Drachm
return this / other;
@:op( A%B) inline public function modulo(other : Float) : Drachm
return this % other;
@:op(A==B) inline public function equal(other : Drachm) : Bool
return this == other;
public function nearEqual(other : Drachm) : Bool
return Floats.nearEqual(this, other.toFloat());
@:op(A!=B) inline public function notEqual(other : Drachm) : Bool
return this != other;
@:op( A<B) inline public function less(other : Drachm) : Bool
return this < other.toFloat();
@:op(A<=B) inline public function lessEqual(other : Drachm) : Bool
return this <= other.toFloat();
@:op( A>B) inline public function more(other : Drachm) : Bool
return this > other.toFloat();
@:op(A>=B) inline public function moreEqual(other : Drachm) : Bool
return this >= other.toFloat();
@:to inline public function toFloat() : Float
return this;
@:to inline public function toMegagram() : Megagram
return this * 1.7718451953125e-06;
@:to inline public function toKilogram() : Kilogram
return this * 0.0017718451953125;
@:to inline public function toGram() : Gram
return this * 1.7718451953125;
@:to inline public function toCentigram() : Centigram
return this * 177.18451953125;
@:to inline public function toMilligram() : Milligram
return this * 1771.8451953125;
@:to inline public function toMicrogram() : Microgram
return this * 1771845.1953125;
@:to inline public function toNanogram() : Nanogram
return this * 1771845195.3125;
@:to inline public function toPicogram() : Picogram
return this * 1771845195312.5;
@:to inline public function toTon() : Ton
return this * 1.74386160714286e-06;
@:to inline public function toHundredweight() : Hundredweight
return this * 3.48772321428571e-05;
@:to inline public function toQuarter() : Quarter
return this * 0.000139508928571429;
@:to inline public function toStone() : Stone
return this * 0.000279017857142857;
@:to inline public function toPound() : Pound
return this * 0.00390625;
@:to inline public function toOunce() : Ounce
return this * 0.0625;
@:to inline public function toGrain() : Grain
return this * 27.34375;
@:to inline public function toUnifiedAtomicMassUnit() : UnifiedAtomicMassUnit
return this * 1.06703021103864e+24;
@:to inline public function toDalton() : Dalton
return this * 1.06703021103864e+24;
@:to inline public function toPlankMass() : PlankMass
return this * 81407.6294302576;
@:to inline public function toSlug() : Slug
return this * 0.00012140996108529;
@:to inline public function toSolarMass() : SolarMass
return this * 8.91023708386764e-34;
@:to inline public function toString() : String
return this + symbol;
public static inline var symbol : String = "dr";
}