Golang math.Sinh() Function with Examples

Golang | math.Sinh() Function: Here, we are going to learn about the Sinh() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 03, 2021

math.Sinh()

The Sinh() function is an inbuilt function of the math package which is used to get the hyperbolic sine of the given parameter.

It accepts a parameter (x) and returns the hyperbolic sine of x.

Syntax:

func Sinh(x float64) float64

Parameter(s):

  • x : The value whose hyperbolic sine is to be found.

Return Value:

The return type of Sinh() function is a float64, it returns the hyperbolic sine of the given value.

Special cases:

  • Sinh(±0) = ±0
    If the parameter is ±0, the function returns ±0.
  • Sinh(±Inf) = ±Inf
    If the parameter is ±Inf, the function returns ±Inf.
  • Sinh(NaN) = NaN
    If the parameter is NaN, the function returns NaN.

Example 1:

// Golang program to demonstrate the
// example of math.Sinh() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Sinh(1))
	fmt.Println(math.Sinh(0.23))
	fmt.Println(math.Sinh(-1))
	fmt.Println(math.Sinh(-0.23))
	fmt.Println(math.Sinh(-1.23))
	fmt.Println(math.Sinh(1.23))
	fmt.Println(math.Sinh(math.Pi))
	fmt.Println(math.Sinh(0))
	fmt.Println(math.Sinh(math.Inf(1)))
	fmt.Println(math.Sinh(math.Inf(-1)))
	fmt.Println(math.Sinh(math.NaN()))
}

Output:

1.1752011936438014
0.23203320371307193
-1.1752011936438014
-0.23203320371307193
-1.564468479304407
1.564468479304407
11.548739357257748
0
+Inf
-Inf
NaN

Example 2:

// Golang program to demonstrate the
// example of math.Sinh() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var SinhX float64

	x = 0
	SinhX = math.Sinh(x)
	fmt.Printf("Hyperbolic sine of %.2f is %.2f\n", x, SinhX)

	x = 0.23
	SinhX = math.Sinh(x)
	fmt.Printf("Hyperbolic sine of %.2f is %.2f\n", x, SinhX)

	x = 1
	SinhX = math.Sinh(x)
	fmt.Printf("Hyperbolic sine of %.2f is %.2f\n", x, SinhX)

	x = -0.23
	SinhX = math.Sinh(x)
	fmt.Printf("Hyperbolic sine of %.2f is %.2f\n", x, SinhX)

	x = -2
	SinhX = math.Sinh(x)
	fmt.Printf("Hyperbolic sine of %.2f is %.2f\n", x, SinhX)

	x = math.Pi
	SinhX = math.Sinh(x)
	fmt.Printf("Hyperbolic sine of %.2f is %.2f\n", x, SinhX)
}

Output:

Hyperbolic sine of 0.00 is 0.00
Hyperbolic sine of 0.23 is 0.23
Hyperbolic sine of 1.00 is 1.18
Hyperbolic sine of -0.23 is -0.23
Hyperbolic sine of -2.00 is -3.63
Hyperbolic sine of 3.14 is 11.55

Golang math Package Constants and Functions »





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.