Skip to main content

tanh

1. TANH Function

The TANH function in H2 database is used to calculate the hyperbolic tangent of a given value.

2. Syntax

The syntax for the TANH function in H2 database is as follows:

TANH(value)

Arguments

  • value: The value for which the hyperbolic tangent needs to be calculated. It should be a numeric value.

Return

  • The TANH function returns the hyperbolic tangent of the given value.

3. Notes

  • The TANH function in H2 database calculates the hyperbolic tangent using the formula: (e^x - e^(-x)) / (e^x + e^(-x)), where e is the base of the natural logarithm.
  • If the input value is not a number or exceeds the numeric range, the TANH function will return NULL.
  • Ensure that you are using the correct syntax and datatype while using the TANH function to avoid errors.

4. Examples

Here are a few examples demonstrating the usage of the TANH function in H2 database:

Example 1 - Calculating the hyperbolic tangent of 1:

SELECT TANH(1) AS tanh_value;

Output:

tanh_value
----------
0.7615941559557649

Example 2 - Calculating the hyperbolic tangent of values stored in a column:

CREATE TABLE data (
id INT PRIMARY KEY,
value DOUBLE
);

INSERT INTO data VALUES (1, 0.5), (2, 1), (3, -0.5);

SELECT id, value, TANH(value) AS tanh_value
FROM data;

Output:

id | value |   tanh_value   
---+-------+----------------
1 | 0.5 | 0.462117157260
2 | 1 | 0.761594155955
3 | -0.5 | -0.462117157260
  • sinh - Calculate hyperbolic sine
  • cosh - Calculate hyperbolic cosine