Trigonometric functions: Difference between revisions

Content deleted Content added
Added BBC BASIC
Sonia (talk | contribs)
Go solution
Line 599: Line 599:
COSH(x) ! Hyperbolic cosine
COSH(x) ! Hyperbolic cosine
TANH(x) ! Hyperbolic tangent</lang>
TANH(x) ! Hyperbolic tangent</lang>
=={{header|Go}}==
The Go math package provides the constant pi and the six trigonometric functions called for by the task. The functions all use the float64 type and work in radians. It also provides a Sincos function.
<lang go>package main

import (
"fmt"
"math"
)

const d = 30.
const r = d * math.Pi / 180

var s = .5
var c = math.Sqrt(3) / 2
var t = 1 / math.Sqrt(3)

func main() {
fmt.Printf("sin(%9.6f deg) = %f\n", d, math.Sin(d*math.Pi/180))
fmt.Printf("sin(%9.6f rad) = %f\n", r, math.Sin(r))
fmt.Printf("cos(%9.6f deg) = %f\n", d, math.Cos(d*math.Pi/180))
fmt.Printf("cos(%9.6f rad) = %f\n", r, math.Cos(r))
fmt.Printf("tan(%9.6f deg) = %f\n", d, math.Tan(d*math.Pi/180))
fmt.Printf("tan(%9.6f rad) = %f\n", r, math.Tan(r))
fmt.Printf("asin(%f) = %9.6f deg\n", s, math.Asin(s)*180/math.Pi)
fmt.Printf("asin(%f) = %9.6f rad\n", s, math.Asin(s))
fmt.Printf("acos(%f) = %9.6f deg\n", c, math.Acos(c)*180/math.Pi)
fmt.Printf("acos(%f) = %9.6f rad\n", c, math.Acos(c))
fmt.Printf("atan(%f) = %9.6f deg\n", t, math.Atan(t)*180/math.Pi)
fmt.Printf("atan(%f) = %9.6f rad\n", t, math.Atan(t))
}</lang>
Output:
<pre>
sin(30.000000 deg) = 0.500000
sin( 0.523599 rad) = 0.500000
cos(30.000000 deg) = 0.866025
cos( 0.523599 rad) = 0.866025
tan(30.000000 deg) = 0.577350
tan( 0.523599 rad) = 0.577350
asin(0.500000) = 30.000000 deg
asin(0.500000) = 0.523599 rad
acos(0.866025) = 30.000000 deg
acos(0.866025) = 0.523599 rad
atan(0.577350) = 30.000000 deg
atan(0.577350) = 0.523599 rad
</pre>


=={{header|Groovy}}==
=={{header|Groovy}}==