2023-02-13 18:29:22 +03:00
|
|
|
|
|
2024-05-08 14:47:54 +03:00
|
|
|
|
# Convert Fahrenheit to Celsius
|
2023-02-13 18:29:22 +03:00
|
|
|
|
export def f-to-c [
|
|
|
|
|
fahren: number # Degrees Fahrenheit
|
|
|
|
|
--round(-r): int = 2 # Digits of precision to round to
|
|
|
|
|
] {
|
|
|
|
|
# (100°F − 32) × 5/9 = 37.778°C
|
2023-09-20 20:13:52 +03:00
|
|
|
|
let $n = if ($fahren | describe) == "float" {$fahren} else {$fahren | into float }
|
2024-05-08 14:47:54 +03:00
|
|
|
|
let celsius = ((( $n - 32.) * 5 / 9. ) | math round -p $round )
|
|
|
|
|
$"($fahren) °F is ($celsius) °C"
|
2023-02-13 18:29:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Convert Fahrenheit to Kelvin
|
|
|
|
|
export def f-to-k [
|
|
|
|
|
fahren: number # Degrees Fahrenheit
|
|
|
|
|
--round(-r): int = 2 # Digits of precision to round to
|
|
|
|
|
] {
|
|
|
|
|
# (100°F − 32) × 5/9 + 273.15 = 310.928K
|
|
|
|
|
|
2023-09-20 20:13:52 +03:00
|
|
|
|
let $n = if ($fahren | describe) == "float" {$fahren} else {$fahren | into float }
|
2023-02-13 18:29:22 +03:00
|
|
|
|
let kelvin = ((($n - 32) * 5 / 9 + 273.15)| math round -p $round )
|
|
|
|
|
$"($fahren) °F is ($kelvin) °K"
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 14:47:54 +03:00
|
|
|
|
# Convert Celsius to Fahrenheit
|
2023-02-13 18:29:22 +03:00
|
|
|
|
export def c-to-f [
|
2024-05-08 14:47:54 +03:00
|
|
|
|
celsius: number # Degrees Celsius
|
2023-02-13 18:29:22 +03:00
|
|
|
|
--round(-r): int = 2 # Digits of precision to round to
|
|
|
|
|
] {
|
|
|
|
|
# (100°C × 9/5) + 32 = 212°F
|
|
|
|
|
|
2024-05-08 14:47:54 +03:00
|
|
|
|
let $n = if ($celsius | describe) == "float" {$celsius} else {$celsius | into float }
|
2023-02-13 18:29:22 +03:00
|
|
|
|
let fahren = ((($n * 9 / 5) + 32) | math round -p $round )
|
2024-05-08 14:47:54 +03:00
|
|
|
|
$"($celsius) °C is ($fahren) °F"
|
2023-02-13 18:29:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 14:47:54 +03:00
|
|
|
|
# Convert Celsius to Kelvin
|
2023-02-13 18:29:22 +03:00
|
|
|
|
export def c-to-k [
|
2024-05-08 14:47:54 +03:00
|
|
|
|
celsius: number # Degrees Celsius
|
2023-02-13 18:29:22 +03:00
|
|
|
|
--round(-r): int = 2 # Digits of precision to round to
|
|
|
|
|
] {
|
|
|
|
|
# 100°C + 273.15 = 373.15K
|
|
|
|
|
|
|
|
|
|
|
2024-05-08 14:47:54 +03:00
|
|
|
|
let $n = if ($celsius | describe) == "float" {$celsius} else {$celsius | into float }
|
2023-02-13 18:29:22 +03:00
|
|
|
|
let kelvin = (($n + 273.15) | math round -p $round )
|
2024-05-08 14:47:54 +03:00
|
|
|
|
$"($celsius) °C is ($kelvin) °K"
|
2023-02-13 18:29:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Convert Kelvin to Fahrenheit
|
|
|
|
|
export def k-to-f [
|
|
|
|
|
kelvin:number # Degrees Fahrenheit
|
|
|
|
|
--round(-r): int = 2 # Digits of precision to round to
|
|
|
|
|
] {
|
|
|
|
|
# (100K − 273.15) × 9/5 + 32 = -279.7°F
|
|
|
|
|
|
2023-09-20 20:13:52 +03:00
|
|
|
|
let $n = if ($kelvin | describe) == "float" {$kelvin} else {$kelvin | into float }
|
2023-02-13 18:29:22 +03:00
|
|
|
|
let fahren = ((($n - 273.15) * 9 / 5 + 32) | math round -p $round )
|
|
|
|
|
$"($kelvin) °K is ($fahren) °F"
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-08 14:47:54 +03:00
|
|
|
|
# Convert Kelvin to Celsius
|
2023-02-13 18:29:22 +03:00
|
|
|
|
export def k-to-c [
|
2024-05-08 14:47:54 +03:00
|
|
|
|
kelvin:number # Degrees Celsius
|
2023-02-13 18:29:22 +03:00
|
|
|
|
--round(-r): int = 2 # Digits of precision to round to
|
|
|
|
|
] {
|
|
|
|
|
# 100K − 273.15 = -173.1°C
|
|
|
|
|
|
2023-09-20 20:13:52 +03:00
|
|
|
|
let $n = if ($kelvin | describe) == "float" {$kelvin} else {$kelvin | into float }
|
2024-05-08 14:47:54 +03:00
|
|
|
|
let celsius = (($n - 273.15) | math round -p $round )
|
|
|
|
|
$"($kelvin) °K is ($celsius) °C"
|
2023-02-13 18:29:22 +03:00
|
|
|
|
}
|