mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-09-11 21:57:33 +03:00
* refactor: ✨ move in one commit
Eveything in modules should probably be changed to `exported` defs.
The idea is to move everything first to keep proper history.
* refactor: 📝 add modules readme (wip)
* refactor: ✨ small move
* refactor: 📝 changed nestring, updated modules readme
* refactor: 📝 to document or not to document
* fix: 🐛 themes
replaced the template to use `main` and regenerated them
from lemnos themes.
* Revert "fix: 🐛 themes"
This reverts commit 4918d3633c
.
* refactor: ✨ introduce sourced
- Created a source `root` in which sourcable demos are stored.
Some might get converted to modules later on.
- Moved some files to bin too.
* fix: 🐛 fehbg.nu
* fix: 🐛 modules/after.nu
* moved some other stuff around
---------
Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
73 lines
2.3 KiB
Plaintext
73 lines
2.3 KiB
Plaintext
|
||
# Convert Fahrenheit to Celcius
|
||
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
|
||
let $n = if ($fahren | describe) == "float" {$fahren} else {$fahren | into decimal }
|
||
let celcius = ((( $n - 32.) * 5 / 9. ) | math round -p $round )
|
||
$"($fahren) °F is ($celcius) °C"
|
||
}
|
||
|
||
# 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
|
||
|
||
let $n = if ($fahren | describe) == "float" {$fahren} else {$fahren | into decimal }
|
||
let kelvin = ((($n - 32) * 5 / 9 + 273.15)| math round -p $round )
|
||
$"($fahren) °F is ($kelvin) °K"
|
||
}
|
||
|
||
# Convert Celcius to Fahrenheit
|
||
export def c-to-f [
|
||
celcius: number # Degrees Celcius
|
||
--round(-r): int = 2 # Digits of precision to round to
|
||
] {
|
||
# (100°C × 9/5) + 32 = 212°F
|
||
|
||
let $n = if ($celcius | describe) == "float" {$celcius} else {$celcius | into decimal }
|
||
let fahren = ((($n * 9 / 5) + 32) | math round -p $round )
|
||
$"($celcius) °C is ($fahren) °F"
|
||
}
|
||
|
||
# Convert Celcius to Kelvin
|
||
export def c-to-k [
|
||
celcius: number # Degrees Celcius
|
||
--round(-r): int = 2 # Digits of precision to round to
|
||
] {
|
||
# 100°C + 273.15 = 373.15K
|
||
|
||
|
||
let $n = if ($celcius | describe) == "float" {$celcius} else {$celcius | into decimal }
|
||
let kelvin = (($n + 273.15) | math round -p $round )
|
||
$"($celcius) °C is ($kelvin) °K"
|
||
}
|
||
|
||
# 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
|
||
|
||
let $n = if ($kelvin | describe) == "float" {$kelvin} else {$kelvin | into decimal }
|
||
let fahren = ((($n - 273.15) * 9 / 5 + 32) | math round -p $round )
|
||
$"($kelvin) °K is ($fahren) °F"
|
||
}
|
||
|
||
# Convert Kelvin to Celcius
|
||
export def k-to-c [
|
||
kelvin:number # Degrees Celcius
|
||
--round(-r): int = 2 # Digits of precision to round to
|
||
] {
|
||
# 100K − 273.15 = -173.1°C
|
||
|
||
let $n = if ($kelvin | describe) == "float" {$kelvin} else {$kelvin | into decimal }
|
||
let celcius = (($n - 273.15) | math round -p $round )
|
||
$"($kelvin) °K is ($celcius) °C"
|
||
}
|