60 lines
1.7 KiB
Odin
60 lines
1.7 KiB
Odin
package quantity
|
|
|
|
import "base:intrinsics"
|
|
|
|
//----- Volts ----------------------------------
|
|
Volts :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
@(private = "file")
|
|
volts_to_milli_volts :: #force_inline proc "contextless" (
|
|
volts: Volts($V),
|
|
) -> Milli_Volts(V) where intrinsics.type_is_numeric(V) {
|
|
return Milli_Volts(V){volts.v * MILLI}
|
|
}
|
|
|
|
//----- Millivolts ----------------------------------
|
|
Milli_Volts :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
|
v: V,
|
|
}
|
|
|
|
@(private = "file")
|
|
milli_volts_to_volts :: #force_inline proc "contextless" (
|
|
milli_volts: Milli_Volts($V),
|
|
) -> Volts(V) where intrinsics.type_is_numeric(V) {
|
|
return Volts(V){milli_volts.v / MILLI}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ----- Conversion Overloads ------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
to_volts :: proc {
|
|
milli_volts_to_volts,
|
|
}
|
|
|
|
to_milli_volts :: proc {
|
|
volts_to_milli_volts,
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
// ----- Tests ------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
import "core:testing"
|
|
|
|
@(test)
|
|
test_volts_to_milli_volts :: proc(t: ^testing.T) {
|
|
volts := Volts(int){1}
|
|
milli_volts := to_milli_volts(volts)
|
|
|
|
testing.expect_value(t, milli_volts, Milli_Volts(int){1000})
|
|
}
|
|
|
|
@(test)
|
|
test_milli_volts_to_volts :: proc(t: ^testing.T) {
|
|
milli_volts := Milli_Volts(int){1000}
|
|
volts := to_volts(milli_volts)
|
|
|
|
testing.expect_value(t, volts, Volts(int){1})
|
|
}
|