Browse Source

tempconv

pull/1/head
dewjjj 8 months ago
parent
commit
43e21fdf13
  1. 2
      README.md
  2. 13
      kelvins/kelvins.go
  3. 8
      tempconv/conv.go
  4. 15
      tempconv/tempconv.go

2
README.md

@ -15,4 +15,4 @@
|11|new|new函数案例一|
|12|gcd|最大公约数|
|13|type|类型别名|
|14|||
|14|tempconv&kelvins|开尔文温度转换|

13
kelvins/kelvins.go

@ -0,0 +1,13 @@
package main
import (
"fmt"
"tempconv"
)
func main() {
fmt.Println("Kelvins~")
fmt.Printf("Kelvins AbsoluteZero: %v~\n", tempconv.AbsoluteZeroK)
fmt.Println(tempconv.KtoC(tempconv.AbsoluteZeroK))
fmt.Printf("%g\n", tempconv.KtoC(tempconv.AbsoluteZeroK))
}

8
tempconv/conv.go

@ -0,0 +1,8 @@
package tempconv
func KtoC(k Kelvins) Celsius {
return Celsius(k - 273.15)
}
func CtoK(c Celsius) Kelvins {
return Kelvins(c + 273.15)
}

15
tempconv/tempconv.go

@ -0,0 +1,15 @@
package tempconv
import "fmt"
type Kelvins float64
type Celsius float64
const (
AbsoluteZeroK Kelvins = 0
FreezingK Kelvins = 273.15
boilingK Kelvins = 373.15
)
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
func (k Kelvins) String() string { return fmt.Sprintf("%g°C", k) }
Loading…
Cancel
Save