1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::{unit, unit_conversion, unit_family};

unit!(Celsius: float);
unit!(Fahrenheit: float);
unit!(Kelvin: float);

unit_conversion!(Celsius(float) <-> Fahrenheit(float) ~ celsius_to_fahrenheit);
unit_conversion!(Celsius(float) <-> Kelvin(float) ~ celsius_to_kelvin);
unit_conversion!(Fahrenheit(float) <-> Kelvin(float) ~ fahrenheit_to_kelvin);

unit_family!(Temperature(Celsius): Fahrenheit, Kelvin);

fn celsius_to_fahrenheit(celsius: f64) -> f64 {
    celsius.mul_add(1.8, 32.0)
}

fn celsius_to_kelvin(celsius: f64) -> f64 {
    celsius + 273.15
}

fn fahrenheit_to_kelvin(fahrenheit: f64) -> f64 {
    (fahrenheit + 459.67) * (5.0 / 9.0)
}