forked from fponticelli/thx.unit
/
Fahrenheit.hx
64 lines (54 loc) · 2.33 KB
/
Fahrenheit.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
package thx.unit.temperature;
import thx.core.Floats;
// TODO parse string
abstract Fahrenheit(Float) {
@:from inline static public function floatToFahrenheit(value : Float) : Fahrenheit
return new Fahrenheit(value);
function new(value : Float)
this = value;
@:op( -A ) inline public function negate() : Fahrenheit
return -this;
@:op( A+B) inline public function add(other : Fahrenheit) : Fahrenheit
return this + other.toFloat();
@:op( A-B) inline public function subtract(other : Fahrenheit) : Fahrenheit
return this - other.toFloat();
@:op( A*B) inline public function multiply(other : Float) : Fahrenheit
return this * other;
@:op( A/B) inline public function divide(other : Float) : Fahrenheit
return this / other;
@:op( A%B) inline public function modulo(other : Float) : Fahrenheit
return this % other;
@:op(A==B) inline public function equal(other : Fahrenheit) : Bool
return this == other;
public function nearEqual(other : Fahrenheit) : Bool
return Floats.nearEqual(this, other.toFloat());
@:op(A!=B) inline public function notEqual(other : Fahrenheit) : Bool
return this != other;
@:op( A<B) inline public function less(other : Fahrenheit) : Bool
return this < other.toFloat();
@:op(A<=B) inline public function lessEqual(other : Fahrenheit) : Bool
return this <= other.toFloat();
@:op( A>B) inline public function more(other : Fahrenheit) : Bool
return this > other.toFloat();
@:op(A>=B) inline public function moreEqual(other : Fahrenheit) : Bool
return this >= other.toFloat();
@:to inline public function toFloat() : Float
return this;
@:to inline public function toCelsius() : Celsius
return (this - 32) * 5/9;
@:to inline public function toKelvin() : Kelvin
return toCelsius().toKelvin();
@:to inline public function toRankine() : Rankine
return toCelsius().toRankine();
@:to inline public function toDelisle() : Delisle
return toCelsius().toDelisle();
@:to inline public function toNewton() : Newton
return toCelsius().toNewton();
@:to inline public function toReaumur() : Reaumur
return toCelsius().toReaumur();
@:to inline public function toRomer() : Romer
return toCelsius().toRomer();
@:to inline public function toString() : String
return this + symbol;
public static inline var symbol : String = "°F";
}