역삼각함수란 삼각함수의 역함수를 의미하고,
역쌍곡선함수란 쌍곡선함수의 역함수를 의미한다.
수학에서 sin 함수의 역함수는 arcsin 으로 표기되는데,
Go 언어에서는 math.Asin() 함수로 구현되어 있다.
/*
* Filename: testArcSine.go
*
* Execute: go run testArcSine.go
*
* Or
*
* Compile: go build testArcSine.go
* Execute: testArcSine
*
* Date: 2013. 1. 1.
* Copyright (c) pkim _AT_ scripts.pe.kr
*/
package main
import (
"fmt"
"math"
)
func asinh(x float64) float64 {
y := math.Log(x + math.Sqrt(x*x + 1))
return y
}
func acosh(x float64) float64 {
y := math.Log(x + math.Sqrt(x*x - 1))
return y
}
func main() {
x := -0.9
y := math.Asin(x)
fmt.Printf("y = asin(%g) = %.9f\n", x, y)
fmt.Printf("sin(y) = sin(%.9f) = %g\n", y, math.Sin(y))
fmt.Printf("\n")
x = 1.1
u := acosh(x)
fmt.Printf("u = acosh(%g) = %.10f\n", x, u)
v := asinh(x)
fmt.Printf("v = asinh(%g) = %.10f\n", x, v)
fmt.Printf("cosh(u) = cosh(%.10f) = %g\n", u, math.Cosh(u))
fmt.Printf("sinh(v) = sinh(%.10f) = %g\n", v, math.Sinh(v))
}
/*
Output:
y = asin(-0.9) = -1.119769515
sin(y) = sin(-1.119769515) = -0.9
u = acosh(1.1) = 0.4435682544
v = asinh(1.1) = 0.9503469298
cosh(u) = cosh(0.4435682544) = 1.1
sinh(v) = sinh(0.9503469298) = 1.1
*/
'프로그래밍 > Go' 카테고리의 다른 글
이진 파일을 읽어서 16진수로 보여주는 HexView 소스 with Go (0) | 2013.08.05 |
---|---|
Go 언어로 평방근, 입방근, n제곱근 구하는 함수를 구현하고 테스트하기 (0) | 2013.01.12 |
Go 언어로 30!(30팩토리얼) 까지 정확하게 계산하기 (0) | 2012.06.29 |
Go 언어로 복소수 계산하기 (0) | 2012.06.28 |
Go 언어의 int64 타입으로 계산 가능한 최대 팩토리얼은? (0) | 2012.06.28 |