Added mass and remove unecesary private
This commit is contained in:
@@ -0,0 +1,774 @@
|
||||
package quantity
|
||||
|
||||
import "base:intrinsics"
|
||||
|
||||
GRAMS_PER_POUND :: 453.59237
|
||||
OUNCES_PER_POUND :: 16
|
||||
GRAMS_PER_OUNCE :: GRAMS_PER_POUND / OUNCES_PER_POUND
|
||||
|
||||
KILO_GRAMS_PER_POUND :: GRAMS_PER_POUND / KILO
|
||||
MILLI_GRAMS_PER_POUND :: GRAMS_PER_POUND * MILLI
|
||||
MICRO_GRAMS_PER_POUND :: GRAMS_PER_POUND * MICRO
|
||||
NANO_GRAMS_PER_POUND :: GRAMS_PER_POUND * NANO
|
||||
|
||||
KILO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE / KILO
|
||||
MILLI_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * MILLI
|
||||
MICRO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * MICRO
|
||||
NANO_GRAMS_PER_OUNCE :: GRAMS_PER_OUNCE * NANO
|
||||
|
||||
//----- Grams ----------------------------------
|
||||
Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||
grams: Grams($V),
|
||||
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Kilo_Grams(V){grams.v / KILO}
|
||||
}
|
||||
|
||||
// Prefer the to_milli_grams procedure group.
|
||||
grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||
grams: Grams($V),
|
||||
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Grams(V){grams.v * MILLI}
|
||||
}
|
||||
|
||||
// Prefer the to_micro_grams procedure group.
|
||||
grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||
grams: Grams($V),
|
||||
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Micro_Grams(V){grams.v * MICRO}
|
||||
}
|
||||
|
||||
// Prefer the to_nano_grams procedure group.
|
||||
grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||
grams: Grams($V),
|
||||
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Nano_Grams(V){grams.v * NANO}
|
||||
}
|
||||
|
||||
// Prefer the to_pounds procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
grams_to_pounds :: #force_inline proc "contextless" (
|
||||
grams: Grams($V),
|
||||
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||
return Pounds(V){grams.v / GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_ounces procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
grams_to_ounces :: #force_inline proc "contextless" (
|
||||
grams: Grams($V),
|
||||
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||
return Ounces(V){grams.v / GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
//----- Kilograms ----------------------------------
|
||||
Kilo_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_grams procedure group.
|
||||
kilo_grams_to_grams :: #force_inline proc "contextless" (
|
||||
kilo_grams: Kilo_Grams($V),
|
||||
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Grams(V){kilo_grams.v * KILO}
|
||||
}
|
||||
|
||||
// Prefer the to_milli_grams procedure group.
|
||||
kilo_grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||
kilo_grams: Kilo_Grams($V),
|
||||
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Grams(V){kilo_grams.v * (KILO * MILLI)}
|
||||
}
|
||||
|
||||
// Prefer the to_micro_grams procedure group.
|
||||
kilo_grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||
kilo_grams: Kilo_Grams($V),
|
||||
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Micro_Grams(V){kilo_grams.v * (KILO * MICRO)}
|
||||
}
|
||||
|
||||
// Prefer the to_nano_grams procedure group.
|
||||
kilo_grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||
kilo_grams: Kilo_Grams($V),
|
||||
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Nano_Grams(V){kilo_grams.v * (KILO * NANO)}
|
||||
}
|
||||
|
||||
// Prefer the to_pounds procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
kilo_grams_to_pounds :: #force_inline proc "contextless" (
|
||||
kilo_grams: Kilo_Grams($V),
|
||||
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||
return Pounds(V){kilo_grams.v / KILO_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_ounces procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
kilo_grams_to_ounces :: #force_inline proc "contextless" (
|
||||
kilo_grams: Kilo_Grams($V),
|
||||
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||
return Ounces(V){kilo_grams.v / KILO_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
//----- Milligrams ----------------------------------
|
||||
Milli_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
milli_grams_to_grams :: #force_inline proc "contextless" (
|
||||
milli_grams: Milli_Grams($V),
|
||||
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Grams(V){milli_grams.v / MILLI}
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
milli_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||
milli_grams: Milli_Grams($V),
|
||||
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Kilo_Grams(V){milli_grams.v / (KILO * MILLI)}
|
||||
}
|
||||
|
||||
// Prefer the to_micro_grams procedure group.
|
||||
milli_grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||
milli_grams: Milli_Grams($V),
|
||||
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Micro_Grams(V){milli_grams.v * (MICRO / MILLI)}
|
||||
}
|
||||
|
||||
// Prefer the to_nano_grams procedure group.
|
||||
milli_grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||
milli_grams: Milli_Grams($V),
|
||||
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Nano_Grams(V){milli_grams.v * (NANO / MILLI)}
|
||||
}
|
||||
|
||||
// Prefer the to_pounds procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
milli_grams_to_pounds :: #force_inline proc "contextless" (
|
||||
milli_grams: Milli_Grams($V),
|
||||
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||
return Pounds(V){milli_grams.v / MILLI_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_ounces procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
milli_grams_to_ounces :: #force_inline proc "contextless" (
|
||||
milli_grams: Milli_Grams($V),
|
||||
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||
return Ounces(V){milli_grams.v / MILLI_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
//----- Micrograms ----------------------------------
|
||||
Micro_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_grams_to_grams :: #force_inline proc "contextless" (
|
||||
micro_grams: Micro_Grams($V),
|
||||
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Grams(V){micro_grams.v / MICRO}
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||
micro_grams: Micro_Grams($V),
|
||||
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Kilo_Grams(V){micro_grams.v / (KILO * MICRO)}
|
||||
}
|
||||
|
||||
// Prefer the to_milli_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||
micro_grams: Micro_Grams($V),
|
||||
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Grams(V){micro_grams.v / (MICRO / MILLI)}
|
||||
}
|
||||
|
||||
// Prefer the to_nano_grams procedure group.
|
||||
micro_grams_to_nano_grams :: #force_inline proc "contextless" (
|
||||
micro_grams: Micro_Grams($V),
|
||||
) -> Nano_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Nano_Grams(V){micro_grams.v * (NANO / MICRO)}
|
||||
}
|
||||
|
||||
// Prefer the to_pounds procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_grams_to_pounds :: #force_inline proc "contextless" (
|
||||
micro_grams: Micro_Grams($V),
|
||||
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||
return Pounds(V){micro_grams.v / MICRO_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_ounces procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_grams_to_ounces :: #force_inline proc "contextless" (
|
||||
micro_grams: Micro_Grams($V),
|
||||
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||
return Ounces(V){micro_grams.v / MICRO_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
//----- Nanograms ----------------------------------
|
||||
Nano_Grams :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
nano_grams_to_grams :: #force_inline proc "contextless" (
|
||||
nano_grams: Nano_Grams($V),
|
||||
) -> Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Grams(V){nano_grams.v / NANO}
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
nano_grams_to_kilo_grams :: #force_inline proc "contextless" (
|
||||
nano_grams: Nano_Grams($V),
|
||||
) -> Kilo_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Kilo_Grams(V){nano_grams.v / (KILO * NANO)}
|
||||
}
|
||||
|
||||
// Prefer the to_milli_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
nano_grams_to_milli_grams :: #force_inline proc "contextless" (
|
||||
nano_grams: Nano_Grams($V),
|
||||
) -> Milli_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Grams(V){nano_grams.v / (NANO / MILLI)}
|
||||
}
|
||||
|
||||
// Prefer the to_micro_grams procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
nano_grams_to_micro_grams :: #force_inline proc "contextless" (
|
||||
nano_grams: Nano_Grams($V),
|
||||
) -> Micro_Grams(V) where intrinsics.type_is_numeric(V) {
|
||||
return Micro_Grams(V){nano_grams.v / (NANO / MICRO)}
|
||||
}
|
||||
|
||||
// Prefer the to_pounds procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
nano_grams_to_pounds :: #force_inline proc "contextless" (
|
||||
nano_grams: Nano_Grams($V),
|
||||
) -> Pounds(V) where intrinsics.type_is_float(V) {
|
||||
return Pounds(V){nano_grams.v / NANO_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_ounces procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
nano_grams_to_ounces :: #force_inline proc "contextless" (
|
||||
nano_grams: Nano_Grams($V),
|
||||
) -> Ounces(V) where intrinsics.type_is_float(V) {
|
||||
return Ounces(V){nano_grams.v / NANO_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
//----- Pounds ----------------------------------
|
||||
Pounds :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_grams procedure group.
|
||||
pounds_to_grams :: #force_inline proc "contextless" (
|
||||
pounds: Pounds($V),
|
||||
) -> Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Grams(V){pounds.v * GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_grams procedure group.
|
||||
pounds_to_kilo_grams :: #force_inline proc "contextless" (
|
||||
pounds: Pounds($V),
|
||||
) -> Kilo_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Kilo_Grams(V){pounds.v * KILO_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_milli_grams procedure group.
|
||||
pounds_to_milli_grams :: #force_inline proc "contextless" (
|
||||
pounds: Pounds($V),
|
||||
) -> Milli_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Milli_Grams(V){pounds.v * MILLI_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_micro_grams procedure group.
|
||||
pounds_to_micro_grams :: #force_inline proc "contextless" (
|
||||
pounds: Pounds($V),
|
||||
) -> Micro_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Micro_Grams(V){pounds.v * MICRO_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_nano_grams procedure group.
|
||||
pounds_to_nano_grams :: #force_inline proc "contextless" (
|
||||
pounds: Pounds($V),
|
||||
) -> Nano_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Nano_Grams(V){pounds.v * NANO_GRAMS_PER_POUND}
|
||||
}
|
||||
|
||||
// Prefer the to_ounces procedure group.
|
||||
pounds_to_ounces :: #force_inline proc "contextless" (
|
||||
pounds: Pounds($V),
|
||||
) -> Ounces(V) where intrinsics.type_is_numeric(V) {
|
||||
return Ounces(V){pounds.v * OUNCES_PER_POUND}
|
||||
}
|
||||
|
||||
//----- Ounces ----------------------------------
|
||||
Ounces :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_grams procedure group.
|
||||
ounces_to_grams :: #force_inline proc "contextless" (
|
||||
ounces: Ounces($V),
|
||||
) -> Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Grams(V){ounces.v * GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_grams procedure group.
|
||||
ounces_to_kilo_grams :: #force_inline proc "contextless" (
|
||||
ounces: Ounces($V),
|
||||
) -> Kilo_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Kilo_Grams(V){ounces.v * KILO_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
// Prefer the to_milli_grams procedure group.
|
||||
ounces_to_milli_grams :: #force_inline proc "contextless" (
|
||||
ounces: Ounces($V),
|
||||
) -> Milli_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Milli_Grams(V){ounces.v * MILLI_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
// Prefer the to_micro_grams procedure group.
|
||||
ounces_to_micro_grams :: #force_inline proc "contextless" (
|
||||
ounces: Ounces($V),
|
||||
) -> Micro_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Micro_Grams(V){ounces.v * MICRO_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
// Prefer the to_nano_grams procedure group.
|
||||
ounces_to_nano_grams :: #force_inline proc "contextless" (
|
||||
ounces: Ounces($V),
|
||||
) -> Nano_Grams(V) where intrinsics.type_is_float(V) {
|
||||
return Nano_Grams(V){ounces.v * NANO_GRAMS_PER_OUNCE}
|
||||
}
|
||||
|
||||
// Prefer the to_pounds procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
ounces_to_pounds :: #force_inline proc "contextless" (
|
||||
ounces: Ounces($V),
|
||||
) -> Pounds(V) where intrinsics.type_is_numeric(V) {
|
||||
return Pounds(V){ounces.v / OUNCES_PER_POUND}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// ----- Conversion Overloads ------------------------
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
to_grams :: proc {
|
||||
kilo_grams_to_grams,
|
||||
milli_grams_to_grams,
|
||||
micro_grams_to_grams,
|
||||
nano_grams_to_grams,
|
||||
pounds_to_grams,
|
||||
ounces_to_grams,
|
||||
}
|
||||
|
||||
to_kilo_grams :: proc {
|
||||
grams_to_kilo_grams,
|
||||
milli_grams_to_kilo_grams,
|
||||
micro_grams_to_kilo_grams,
|
||||
nano_grams_to_kilo_grams,
|
||||
pounds_to_kilo_grams,
|
||||
ounces_to_kilo_grams,
|
||||
}
|
||||
|
||||
to_milli_grams :: proc {
|
||||
grams_to_milli_grams,
|
||||
kilo_grams_to_milli_grams,
|
||||
micro_grams_to_milli_grams,
|
||||
nano_grams_to_milli_grams,
|
||||
pounds_to_milli_grams,
|
||||
ounces_to_milli_grams,
|
||||
}
|
||||
|
||||
to_micro_grams :: proc {
|
||||
grams_to_micro_grams,
|
||||
kilo_grams_to_micro_grams,
|
||||
milli_grams_to_micro_grams,
|
||||
nano_grams_to_micro_grams,
|
||||
pounds_to_micro_grams,
|
||||
ounces_to_micro_grams,
|
||||
}
|
||||
|
||||
to_nano_grams :: proc {
|
||||
grams_to_nano_grams,
|
||||
kilo_grams_to_nano_grams,
|
||||
milli_grams_to_nano_grams,
|
||||
micro_grams_to_nano_grams,
|
||||
pounds_to_nano_grams,
|
||||
ounces_to_nano_grams,
|
||||
}
|
||||
|
||||
to_pounds :: proc {
|
||||
grams_to_pounds,
|
||||
kilo_grams_to_pounds,
|
||||
milli_grams_to_pounds,
|
||||
micro_grams_to_pounds,
|
||||
nano_grams_to_pounds,
|
||||
ounces_to_pounds,
|
||||
}
|
||||
|
||||
to_ounces :: proc {
|
||||
grams_to_ounces,
|
||||
kilo_grams_to_ounces,
|
||||
milli_grams_to_ounces,
|
||||
micro_grams_to_ounces,
|
||||
nano_grams_to_ounces,
|
||||
pounds_to_ounces,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// ----- Tests ------------------------
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
test_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||
grams := Grams(int){12_000}
|
||||
kilo_grams := to_kilo_grams(grams)
|
||||
|
||||
testing.expect_value(t, kilo_grams, Kilo_Grams(int){12})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||
grams := Grams(int){12}
|
||||
milli_grams := to_milli_grams(grams)
|
||||
|
||||
testing.expect_value(t, milli_grams, Milli_Grams(int){12_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||
grams := Grams(int){12}
|
||||
micro_grams := to_micro_grams(grams)
|
||||
|
||||
testing.expect_value(t, micro_grams, Micro_Grams(int){12_000_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||
grams := Grams(int){12}
|
||||
nano_grams := to_nano_grams(grams)
|
||||
|
||||
testing.expect_value(t, nano_grams, Nano_Grams(int){12_000_000_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_grams_to_pounds :: proc(t: ^testing.T) {
|
||||
grams := Grams(f32){453.59237}
|
||||
pounds := to_pounds(grams)
|
||||
|
||||
testing.expect(t, pounds.v > 0.99 && pounds.v < 1.01)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_grams_to_ounces :: proc(t: ^testing.T) {
|
||||
grams := Grams(f32){28.349523125}
|
||||
ounces := to_ounces(grams)
|
||||
|
||||
testing.expect(t, ounces.v > 0.99 && ounces.v < 1.01)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_kilo_grams_to_grams :: proc(t: ^testing.T) {
|
||||
kilo_grams := Kilo_Grams(int){12}
|
||||
grams := to_grams(kilo_grams)
|
||||
|
||||
testing.expect_value(t, grams, Grams(int){12_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_kilo_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||
kilo_grams := Kilo_Grams(int){5}
|
||||
milli_grams := to_milli_grams(kilo_grams)
|
||||
|
||||
testing.expect_value(t, milli_grams, Milli_Grams(int){5_000_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_kilo_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||
kilo_grams := Kilo_Grams(int){5}
|
||||
micro_grams := to_micro_grams(kilo_grams)
|
||||
|
||||
testing.expect_value(t, micro_grams, Micro_Grams(int){5_000_000_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_kilo_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||
kilo_grams := Kilo_Grams(int){5}
|
||||
nano_grams := to_nano_grams(kilo_grams)
|
||||
|
||||
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000_000_000_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_kilo_grams_to_pounds :: proc(t: ^testing.T) {
|
||||
kilo_grams := Kilo_Grams(f32){0.45359237}
|
||||
pounds := to_pounds(kilo_grams)
|
||||
|
||||
testing.expect(t, pounds.v > 0.99 && pounds.v < 1.01)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_kilo_grams_to_ounces :: proc(t: ^testing.T) {
|
||||
kilo_grams := Kilo_Grams(f32){0.028349523125}
|
||||
ounces := to_ounces(kilo_grams)
|
||||
|
||||
testing.expect(t, ounces.v > 0.99 && ounces.v < 1.01)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_grams_to_grams :: proc(t: ^testing.T) {
|
||||
milli_grams := Milli_Grams(int){12_000}
|
||||
grams := to_grams(milli_grams)
|
||||
|
||||
testing.expect_value(t, grams, Grams(int){12})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||
milli_grams := Milli_Grams(int){5_000_000}
|
||||
kilo_grams := to_kilo_grams(milli_grams)
|
||||
|
||||
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||
milli_grams := Milli_Grams(int){5}
|
||||
micro_grams := to_micro_grams(milli_grams)
|
||||
|
||||
testing.expect_value(t, micro_grams, Micro_Grams(int){5_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||
milli_grams := Milli_Grams(int){5}
|
||||
nano_grams := to_nano_grams(milli_grams)
|
||||
|
||||
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_grams_to_pounds :: proc(t: ^testing.T) {
|
||||
milli_grams := Milli_Grams(f64){453_592.37}
|
||||
pounds := to_pounds(milli_grams)
|
||||
|
||||
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_milli_grams_to_ounces :: proc(t: ^testing.T) {
|
||||
milli_grams := Milli_Grams(f64){28_349.523125}
|
||||
ounces := to_ounces(milli_grams)
|
||||
|
||||
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_micro_grams_to_grams :: proc(t: ^testing.T) {
|
||||
micro_grams := Micro_Grams(int){12_000_000}
|
||||
grams := to_grams(micro_grams)
|
||||
|
||||
testing.expect_value(t, grams, Grams(int){12})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_micro_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||
micro_grams := Micro_Grams(int){5_000_000_000}
|
||||
kilo_grams := to_kilo_grams(micro_grams)
|
||||
|
||||
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_micro_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||
micro_grams := Micro_Grams(int){5_000}
|
||||
milli_grams := to_milli_grams(micro_grams)
|
||||
|
||||
testing.expect_value(t, milli_grams, Milli_Grams(int){5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_micro_grams_to_nano_grams :: proc(t: ^testing.T) {
|
||||
micro_grams := Micro_Grams(int){5}
|
||||
nano_grams := to_nano_grams(micro_grams)
|
||||
|
||||
testing.expect_value(t, nano_grams, Nano_Grams(int){5_000})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_micro_grams_to_pounds :: proc(t: ^testing.T) {
|
||||
micro_grams := Micro_Grams(f64){453_592_370}
|
||||
pounds := to_pounds(micro_grams)
|
||||
|
||||
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_micro_grams_to_ounces :: proc(t: ^testing.T) {
|
||||
micro_grams := Micro_Grams(f64){28_349_523.125}
|
||||
ounces := to_ounces(micro_grams)
|
||||
|
||||
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nano_grams_to_grams :: proc(t: ^testing.T) {
|
||||
nano_grams := Nano_Grams(int){12_000_000_000}
|
||||
grams := to_grams(nano_grams)
|
||||
|
||||
testing.expect_value(t, grams, Grams(int){12})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nano_grams_to_kilo_grams :: proc(t: ^testing.T) {
|
||||
nano_grams := Nano_Grams(int){5_000_000_000_000}
|
||||
kilo_grams := to_kilo_grams(nano_grams)
|
||||
|
||||
testing.expect_value(t, kilo_grams, Kilo_Grams(int){5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nano_grams_to_milli_grams :: proc(t: ^testing.T) {
|
||||
nano_grams := Nano_Grams(int){5_000_000}
|
||||
milli_grams := to_milli_grams(nano_grams)
|
||||
|
||||
testing.expect_value(t, milli_grams, Milli_Grams(int){5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nano_grams_to_micro_grams :: proc(t: ^testing.T) {
|
||||
nano_grams := Nano_Grams(int){5_000}
|
||||
micro_grams := to_micro_grams(nano_grams)
|
||||
|
||||
testing.expect_value(t, micro_grams, Micro_Grams(int){5})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nano_grams_to_pounds :: proc(t: ^testing.T) {
|
||||
nano_grams := Nano_Grams(f64){453_592_370_000}
|
||||
pounds := to_pounds(nano_grams)
|
||||
|
||||
testing.expect(t, pounds.v > 0.9999999 && pounds.v < 1.0000001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_nano_grams_to_ounces :: proc(t: ^testing.T) {
|
||||
nano_grams := Nano_Grams(f64){28_349_523_125}
|
||||
ounces := to_ounces(nano_grams)
|
||||
|
||||
testing.expect(t, ounces.v > 0.9999999 && ounces.v < 1.0000001)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_pounds_to_grams :: proc(t: ^testing.T) {
|
||||
pounds := Pounds(f32){1}
|
||||
grams := to_grams(pounds)
|
||||
|
||||
testing.expect(t, grams.v > 453.59 && grams.v < 453.6)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_pounds_to_kilo_grams :: proc(t: ^testing.T) {
|
||||
pounds := Pounds(f32){1}
|
||||
kilo_grams := to_kilo_grams(pounds)
|
||||
|
||||
testing.expect(t, kilo_grams.v > 0.4535 && kilo_grams.v < 0.4536)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_pounds_to_milli_grams :: proc(t: ^testing.T) {
|
||||
pounds := Pounds(f64){1}
|
||||
milli_grams := to_milli_grams(pounds)
|
||||
|
||||
testing.expect(t, milli_grams.v > 453_592.369 && milli_grams.v < 453_592.371)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_pounds_to_micro_grams :: proc(t: ^testing.T) {
|
||||
pounds := Pounds(f64){1}
|
||||
micro_grams := to_micro_grams(pounds)
|
||||
|
||||
testing.expect(t, micro_grams.v > 453_592_369.9 && micro_grams.v < 453_592_370.1)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_pounds_to_nano_grams :: proc(t: ^testing.T) {
|
||||
pounds := Pounds(f64){1}
|
||||
nano_grams := to_nano_grams(pounds)
|
||||
|
||||
testing.expect(t, nano_grams.v > 453_592_369_999.0 && nano_grams.v < 453_592_370_001.0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_pounds_to_ounces :: proc(t: ^testing.T) {
|
||||
pounds := Pounds(int){2}
|
||||
ounces := to_ounces(pounds)
|
||||
|
||||
testing.expect_value(t, ounces, Ounces(int){32})
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_ounces_to_grams :: proc(t: ^testing.T) {
|
||||
ounces := Ounces(f32){1}
|
||||
grams := to_grams(ounces)
|
||||
|
||||
testing.expect(t, grams.v > 28.34 && grams.v < 28.35)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_ounces_to_kilo_grams :: proc(t: ^testing.T) {
|
||||
ounces := Ounces(f32){1}
|
||||
kilo_grams := to_kilo_grams(ounces)
|
||||
|
||||
testing.expect(t, kilo_grams.v > 0.0283 && kilo_grams.v < 0.0284)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_ounces_to_milli_grams :: proc(t: ^testing.T) {
|
||||
ounces := Ounces(f64){1}
|
||||
milli_grams := to_milli_grams(ounces)
|
||||
|
||||
testing.expect(t, milli_grams.v > 28_349.523 && milli_grams.v < 28_349.524)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_ounces_to_micro_grams :: proc(t: ^testing.T) {
|
||||
ounces := Ounces(f64){1}
|
||||
micro_grams := to_micro_grams(ounces)
|
||||
|
||||
testing.expect(t, micro_grams.v > 28_349_523.124 && micro_grams.v < 28_349_523.126)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_ounces_to_nano_grams :: proc(t: ^testing.T) {
|
||||
ounces := Ounces(f64){1}
|
||||
nano_grams := to_nano_grams(ounces)
|
||||
|
||||
testing.expect(t, nano_grams.v > 28_349_523_124.0 && nano_grams.v < 28_349_523_126.0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_ounces_to_pounds :: proc(t: ^testing.T) {
|
||||
ounces := Ounces(int){32}
|
||||
pounds := to_pounds(ounces)
|
||||
|
||||
testing.expect_value(t, pounds, Pounds(int){2})
|
||||
}
|
||||
+19
-17
@@ -10,14 +10,14 @@ Pascals :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_kilo_pascals procedure group.
|
||||
pascals_to_kilo_pascals :: #force_inline proc "contextless" (
|
||||
pascals: Pascals($V),
|
||||
) -> Kilo_Pascals(V) where intrinsics.type_is_numeric(V) {
|
||||
return Kilo_Pascals(V){pascals.v / KILO}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_torr procedure group.
|
||||
pascals_to_torr :: #force_inline proc "contextless" (
|
||||
pascals: Pascals($V),
|
||||
) -> Torr(V) where intrinsics.type_is_float(V) {
|
||||
@@ -29,15 +29,16 @@ Kilo_Pascals :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_pascals procedure group.
|
||||
kilo_pascals_to_pascals :: #force_inline proc "contextless" (
|
||||
kilo_pascals: Kilo_Pascals($V),
|
||||
) -> Pascals(V) where intrinsics.type_is_numeric(V) {
|
||||
return Pascals(V){kilo_pascals.v * KILO}
|
||||
}
|
||||
|
||||
// Prefer the to_psi procedure group.
|
||||
kilo_pascals_to_psi :: #force_inline proc "contextless" (
|
||||
kilo_pascals: Kilo_Pascals($V),
|
||||
kilo_pascals: Kilo_Pascals($V),
|
||||
) -> Psi(V) where intrinsics.type_is_float(V) {
|
||||
return Psi(V){kilo_pascals.v / KILO_PASCALS_PER_PSI}
|
||||
}
|
||||
@@ -47,7 +48,7 @@ Torr :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_pascals procedure group.
|
||||
torr_to_pascals :: #force_inline proc "contextless" (
|
||||
torr: Torr($V),
|
||||
) -> Pascals(V) where intrinsics.type_is_float(V) {
|
||||
@@ -59,6 +60,7 @@ Psi :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
// Prefer the to_kilo_pascals procedure group.
|
||||
psi_to_kilo_pascals :: #force_inline proc "contextless" (
|
||||
psi: Psi($V),
|
||||
) -> Kilo_Pascals(V) where intrinsics.type_is_float(V) {
|
||||
@@ -79,11 +81,11 @@ to_kilo_pascals :: proc {
|
||||
}
|
||||
|
||||
to_torr :: proc {
|
||||
pascals_to_torr,
|
||||
pascals_to_torr,
|
||||
}
|
||||
|
||||
to_psi :: proc {
|
||||
kilo_pascals_to_psi,
|
||||
kilo_pascals_to_psi,
|
||||
}
|
||||
|
||||
|
||||
@@ -110,25 +112,25 @@ test_kilo_pascals_to_pascals :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_pascals_to_torr :: proc(t: ^testing.T) {
|
||||
pascals := Pascals(f32){1000}
|
||||
torr := to_torr(pascals)
|
||||
pascals := Pascals(f32){1000}
|
||||
torr := to_torr(pascals)
|
||||
|
||||
testing.expect(t, torr.v > 7.49 && torr.v < 7.51)
|
||||
testing.expect(t, torr.v > 7.49 && torr.v < 7.51)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_torr_to_pascals :: proc(t: ^testing.T) {
|
||||
torr := Torr(f32){7.5}
|
||||
pascals := to_pascals(torr)
|
||||
torr := Torr(f32){7.5}
|
||||
pascals := to_pascals(torr)
|
||||
|
||||
testing.expect(t, pascals.v > 999.91 && pascals.v < 999.92)
|
||||
testing.expect(t, pascals.v > 999.91 && pascals.v < 999.92)
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_psi_kilo_pascals :: proc(t: ^testing.T) {
|
||||
psi := Psi(f32){2.5}
|
||||
kilo_pascals := Kilo_Pascals(f32){17.23689323292091}
|
||||
psi := Psi(f32){2.5}
|
||||
kilo_pascals := Kilo_Pascals(f32){17.23689323292091}
|
||||
|
||||
testing.expect(t, to_kilo_pascals(psi).v > 17.22 && to_kilo_pascals(psi).v < 17.24)
|
||||
testing.expect(t, to_psi(kilo_pascals).v > 2.49 && to_psi(kilo_pascals).v < 2.51)
|
||||
testing.expect(t, to_kilo_pascals(psi).v > 17.22 && to_kilo_pascals(psi).v < 17.24)
|
||||
testing.expect(t, to_psi(kilo_pascals).v > 2.49 && to_psi(kilo_pascals).v < 2.51)
|
||||
}
|
||||
|
||||
+11
-10
@@ -30,21 +30,21 @@ Kelvins :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_celsius procedure group.
|
||||
kelvins_to_celsius :: #force_inline proc "contextless" (
|
||||
kelvins: Kelvins($V),
|
||||
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||
return Celsius(V){kelvins.v - kelvins_celsius_offset(V)}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_deci_kelvins procedure group.
|
||||
kelvins_to_deci_kelvins :: #force_inline proc "contextless" (
|
||||
kelvins: Kelvins($V),
|
||||
) -> Deci_Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||
return Deci_Kelvins(V){kelvins.v * DECI}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_fahrenheit procedure group.
|
||||
kelvins_to_fahrenheit :: #force_inline proc "contextless" (
|
||||
kelvins: Kelvins($V),
|
||||
) -> Fahrenheit(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -56,7 +56,7 @@ Deci_Kelvins :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_kelvins procedure group.
|
||||
deci_kelvins_to_kelvins :: #force_inline proc "contextless" (
|
||||
deci_kelvins: Deci_Kelvins($V),
|
||||
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -68,21 +68,22 @@ Celsius :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_kelvins procedure group.
|
||||
celsius_to_kelvins :: #force_inline proc "contextless" (
|
||||
degrees_celsius: Celsius($V),
|
||||
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||
return Kelvins(V){degrees_celsius.v + kelvins_celsius_offset(V)}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_deci_celsius procedure group.
|
||||
celsius_to_deci_celsius :: #force_inline proc "contextless" (
|
||||
degrees_celsius: Celsius($V),
|
||||
) -> Deci_Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||
return Deci_Celsius(V){degrees_celsius.v * DECI}
|
||||
}
|
||||
|
||||
@(private = "file", fast_math = {.Allow_Contract})
|
||||
// Prefer the to_fahrenheit procedure group.
|
||||
@(fast_math = {.Allow_Contract})
|
||||
celsius_to_fahrenheit :: #force_inline proc "contextless" (
|
||||
degrees_celsius: Celsius($V),
|
||||
) -> Fahrenheit(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -98,7 +99,7 @@ Deci_Celsius :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_celsius procedure group.
|
||||
deci_celsius_to_celsius :: #force_inline proc "contextless" (
|
||||
deci_degrees_celsius: Deci_Celsius($V),
|
||||
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -110,7 +111,7 @@ Fahrenheit :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_celsius procedure group.
|
||||
fahrenheit_to_celsius :: #force_inline proc "contextless" (
|
||||
degrees_fahrenheit: Fahrenheit($V),
|
||||
) -> Celsius(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -121,7 +122,7 @@ fahrenheit_to_celsius :: #force_inline proc "contextless" (
|
||||
}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_kelvins procedure group.
|
||||
fahrenheit_to_kelvins :: #force_inline proc "contextless" (
|
||||
degrees_fahrenheit: Fahrenheit($V),
|
||||
) -> Kelvins(V) where intrinsics.type_is_numeric(V) {
|
||||
|
||||
@@ -7,7 +7,7 @@ Volts :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_milli_volts procedure group.
|
||||
volts_to_milli_volts :: #force_inline proc "contextless" (
|
||||
volts: Volts($V),
|
||||
) -> Milli_Volts(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -19,7 +19,7 @@ Milli_Volts :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_volts procedure group.
|
||||
milli_volts_to_volts :: #force_inline proc "contextless" (
|
||||
milli_volts: Milli_Volts($V),
|
||||
) -> Volts(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -30,11 +30,11 @@ milli_volts_to_volts :: #force_inline proc "contextless" (
|
||||
// ----- Conversion Overloads ------------------------
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
to_volts :: proc {
|
||||
milli_volts_to_volts,
|
||||
milli_volts_to_volts,
|
||||
}
|
||||
|
||||
to_milli_volts :: proc {
|
||||
volts_to_milli_volts,
|
||||
volts_to_milli_volts,
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
@@ -52,8 +52,8 @@ test_volts_to_milli_volts :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_milli_volts_to_volts :: proc(t: ^testing.T) {
|
||||
milli_volts := Milli_Volts(int){1000}
|
||||
volts := to_volts(milli_volts)
|
||||
milli_volts := Milli_Volts(int){1000}
|
||||
volts := to_volts(milli_volts)
|
||||
|
||||
testing.expect_value(t, volts, Volts(int){1})
|
||||
testing.expect_value(t, volts, Volts(int){1})
|
||||
}
|
||||
|
||||
+15
-10
@@ -10,21 +10,22 @@ Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_milli_liters procedure group.
|
||||
liters_to_milli_liters :: #force_inline proc "contextless" (
|
||||
liters: Liters($V),
|
||||
) -> Milli_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Liters(V){liters.v * MILLI}
|
||||
}
|
||||
|
||||
@(private = "file", fast_math = {.Allow_Reciprocal})
|
||||
// Prefer the to_gallons procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
liters_to_gallons :: #force_inline proc "contextless" (
|
||||
liters: Liters($V),
|
||||
) -> Gallons(V) where intrinsics.type_is_float(V) {
|
||||
return Gallons(V){liters.v / LITERS_PER_GALLON}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_micro_liters procedure group.
|
||||
liters_to_micro_liters :: #force_inline proc "contextless" (
|
||||
liters: Liters($V),
|
||||
) -> Micro_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -36,14 +37,15 @@ Milli_Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file", fast_math = {.Allow_Reciprocal})
|
||||
// Prefer the to_liters procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
milli_liters_to_liters :: #force_inline proc "contextless" (
|
||||
milli_liters: Milli_Liters($V),
|
||||
) -> Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
return Liters(V){milli_liters.v / MILLI}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_micro_liters procedure group.
|
||||
milli_liters_to_micro_liters :: #force_inline proc "contextless" (
|
||||
milli_liters: Milli_Liters($V),
|
||||
) -> Micro_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
@@ -55,21 +57,24 @@ Micro_Liters :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file", fast_math = {.Allow_Reciprocal})
|
||||
// Prefer the to_liters procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_liters_to_liters :: #force_inline proc "contextless" (
|
||||
micro_liters: Micro_Liters($V),
|
||||
) -> Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
return Liters(V){micro_liters.v / MICRO}
|
||||
}
|
||||
|
||||
@(private = "file", fast_math = {.Allow_Reciprocal})
|
||||
// Prefer the to_milli_liters procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_liters_to_milli_liters :: #force_inline proc "contextless" (
|
||||
micro_liters: Micro_Liters($V),
|
||||
) -> Milli_Liters(V) where intrinsics.type_is_numeric(V) {
|
||||
return Milli_Liters(V){micro_liters.v / (MICRO / MILLI)}
|
||||
}
|
||||
|
||||
@(private = "file", fast_math = {.Allow_Reciprocal})
|
||||
// Prefer the to_gallons procedure group.
|
||||
@(fast_math = {.Allow_Reciprocal})
|
||||
micro_liters_to_gallons :: #force_inline proc "contextless" (
|
||||
micro_liters: Micro_Liters($V),
|
||||
) -> Gallons(V) where intrinsics.type_is_float(V) {
|
||||
@@ -81,14 +86,14 @@ Gallons :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_liters procedure group.
|
||||
gallons_to_liters :: #force_inline proc "contextless" (
|
||||
gallons: Gallons($V),
|
||||
) -> Liters(V) where intrinsics.type_is_float(V) {
|
||||
return Liters(V){gallons.v * LITERS_PER_GALLON}
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_micro_liters procedure group.
|
||||
gallons_to_micro_liters :: #force_inline proc "contextless" (
|
||||
gallons: Gallons($V),
|
||||
) -> Micro_Liters(V) where intrinsics.type_is_float(V) {
|
||||
|
||||
@@ -7,7 +7,7 @@ Liters_Per_Minute :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_gallons_per_minute procedure group.
|
||||
liters_per_minute_to_gallons_per_minute :: #force_inline proc "contextless" (
|
||||
liters_per_minute: Liters_Per_Minute($V),
|
||||
) -> Gallons_Per_Minute(V) where intrinsics.type_is_float(V) {
|
||||
@@ -19,7 +19,7 @@ Gallons_Per_Minute :: struct($V: typeid) where intrinsics.type_is_numeric(V) {
|
||||
v: V,
|
||||
}
|
||||
|
||||
@(private = "file")
|
||||
// Prefer the to_liters_per_minute procedure group.
|
||||
gallons_per_minute_to_liters_per_minute :: #force_inline proc "contextless" (
|
||||
gallons_per_minute: Gallons_Per_Minute($V),
|
||||
) -> Liters_Per_Minute(V) where intrinsics.type_is_float(V) {
|
||||
|
||||
Reference in New Issue
Block a user