For the complete documentation index, see llms.txt. This page is also available as Markdown.

tanh

Use the tanh() function to calculate the hyperbolic tangent of a numeric value.

Syntax

tanh(<number>)

Parameters

Name
Type
Required
Description

number

integer, float

Yes

The numeric value for which to calculate the hyperbolic tangent. Any real number is valid.

Returns

Type: float

Description: The tanh() function returns the hyperbolic tangent of the input value. The resulting value is within the range (-1, 1). If the input is null, the function returns null.

Usage notes

  • Input type: XQL doesn't support NaN or infinite values as input and these value types also can not be returned.

  • Valid Input Range: The tanh() function accepts any real number as input.

  • Null Handling: If the input expression is null, the function returns null.

  • Symmetry: The function is odd, meaning tanh(-x) = -tanh(x).

  • Identity Value: tanh(0) always returns 0.0.

  • Result Range: The output is always strictly between -1 and 1 (exclusive). As x approaches positive infinity, tanh(x) approaches 1.0. As x approaches negative infinity, tanh(x) approaches -1.0.

  • Definition: The hyperbolic tangent is defined as sinh(x) / cosh(x) or (e^x - e^(-x)) / (e^x + e^(-x)).

  • Common Use Cases: This function is typically used within the alter stage for data normalization (squashing values to the range (-1, 1)), neural network activation functions, and scientific computations.

Examples

Example 1: Calculate hyperbolic tangent of literal values

Goal: Calculate the hyperbolic tangent for specific numeric literals to verify known mathematical results.

XQL code:

Explanation: tanh(0) returns 0.0. tanh(1) returns approximately 0.7616, and tanh(-1) returns approximately -0.7616, demonstrating the odd symmetry of the function.

Output:

RESULT1
RESULT2
RESULT3

0.0

0.76159

-0.76159

Example 2: Calculate hyperbolic tangent from a field value

Goal: Calculate the hyperbolic tangent of values stored in a dataset field.

XQL code:

Explanation: This query computes the hyperbolic tangent for each value in the numeric_value field. The result is always between -1 and 1, effectively normalizing the values. No filtering is needed since tanh() accepts any real number.

Output:

EVENT_ID
NUMERIC_VALUE
TANH_RESULT

101

0.0

0.0

102

1.0

0.76159

103

100.0

1.0

Example 3: Use tanh for data normalization

Goal: Normalize large numeric values to the range (-1, 1) using the hyperbolic tangent function.

XQL code:

Explanation: This query first scales numeric_value by dividing by 100, then applies tanh() to squash the result into the range (-1, 1). This is a common normalization technique that preserves the sign and relative magnitude of values while bounding the output.

Output:

EVENT_ID
NUMERIC_VALUE
NORMALIZED_VALUE

101

5.0

0.04996

102

500.0

1.0

103

-200.0

-0.96403

Was this helpful?