Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Funcoes de conversao para Kelvin #109

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion tempconv/tempconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "fmt"

type Celsius float64
type Fahrenheit float64
type Kelvin float64

const (
// AbsoluteZeroC representa a temperatura zero absoluto em Celsius
Expand All @@ -22,8 +23,23 @@ func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
// String imprime uma temperatura 'n' em Fahrenheit no formato n°F
func (f Fahrenheit) String() string { return fmt.Sprintf("%g°F", f) }

// String imprime uma temperatura 'n' em Kelvin no formato n°K
func (k Kelvin) String() string { return fmt.Sprintf("%g°K", k) }

// CToF converte uma temperatura em Celsius para Fahrenheit
func CToF(c Celsius) Fahrenheit { return Fahrenheit(c*9/5 + 32) }

// FToC converte uma temperatura em Fahrenheit para Celsius
func FToC(f Fahrenheit) Celsius { return Celsius((f - 32) * 5 / 9) }
func FToC(f Fahrenheit) Celsius { return Celsius((f - 32) * 5/9) }

// FToK converte uma temperatura em Fahrenheit para Kelvin
func FToK(f Fahrenheit) Kelvin { return Kelvin((f - 32) * 5/9 + 273.15) }

// CToK converte uma temperatura em Celsius para Kelvin
func CToK(c Celsius) Kelvin { return Kelvin(c + 273.15) }

// KToF converte uma temperatura em Kelvin para Fahrenheit
func CToF(k Kelvin) Fahrenheit { return Fahrenheit((k - 273.15) * 9/5 + 32) }

// KToC converte uma temperatura em Kelvin para Celsius
func KToC(k Kelvin) Celsius { return Celsius(k - 273.15) }