Trusted answers to developer questions

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ** tanh() function** returns the

`radians`

.Figure 1 shows the mathematical representation of the `tanh()`

function.

The

`scala.math._`

header file is required for this function.

```
Double tanh(Double number)
```

This function requires a `number`

that represents an `angle`

in `radians`

as a parameter.

You can use the following formula to convert `degrees`

to `radians`

.

```
radians = degrees * ( Pi / 180 )
```

`tanh()`

returns the

- If the parameter value is positive infinity, then it returns 1.
- If the parameter value is negative infinity, then it returns -1.
- If the parameter value is NaN, then it returns NaN.

import scala.math._object Main extends App {//positive number in radiansprintln(s"The value of tanh(2.3) = ${tanh(2.3)}");// negative number in radiansprintln(s"The value of tanh(-2.3) = ${tanh(-2.3)}");//converting the degrees angle into radians and then applying tanh()// degrees = 45.0// PI = 3.14159265// result first converts degrees to radians then apply tanhprintln(s"The value of tanh(45.0) = ${tanh(45.0 * (Pi / 180.0))}");//error outputsprintln(s"The value of tanh(Double.PositiveInfinity) = ${tanh(Double.PositiveInfinity)}");println(s"The value of tanh(Double.NegativeInfinity) = ${tanh(Double.NegativeInfinity)}");println(s"The value of tanh(Double.NaN) = ${tanh(Double.NaN)}");}

RELATED TAGS

scala

math

tangent

communitycreator

CONTRIBUTOR

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses