Acosh¶
Overview¶
The Acosh expression computes the inverse hyperbolic cosine (hyperbolic arccosine) of a numeric value. It implements the mathematical function acosh(x) = ln(x + √(x² - 1)) for input values x ≥ 1, returning NaN for invalid inputs.
Syntax¶
Arguments¶
| Argument | Type | Description |
|---|---|---|
| expr | Numeric | The input expression for which to calculate the inverse hyperbolic cosine |
Return Type¶
Double - Returns a double-precision floating-point number representing the inverse hyperbolic cosine.
Supported Data Types¶
- All numeric types (Int, Long, Float, Double, Decimal)
- Input values are cast to Double for computation
Algorithm¶
- Accepts a single numeric expression as input (child)
- Applies the mathematical formula: ln(x + √(x² - 1))
- Uses
StrictMath.log()for logarithmic computation andMath.sqrt()for square root - Returns NaN for inputs less than 1.0 (mathematically undefined domain)
- Inherits standard null propagation from
UnaryMathExpression
Partitioning Behavior¶
How this expression affects partitioning:
- Preserves partitioning as it's a deterministic unary transformation
- Does not require shuffle operations
- Can be pushed down to individual partitions
Edge Cases¶
- Returns NaN for null inputs (standard null propagation)
- Returns NaN for inputs < 1.0 (outside mathematical domain)
- Returns 0.0 for input value 1.0 (acosh(1) = 0)
- Returns positive infinity for positive infinity input
- Handles negative infinity and negative values by returning NaN
Code Generation¶
This expression supports Tungsten code generation with a custom doGenCode implementation that generates efficient Java code using StrictMath.log() and Math.sqrt() operations directly in the generated bytecode.
Examples¶
-- Basic usage
SELECT ACOSH(1.0); -- Returns 0.0
SELECT ACOSH(2.0); -- Returns ~1.317
SELECT ACOSH(0.5); -- Returns NaN
SELECT ACOSH(NULL); -- Returns NULL
-- With table data
SELECT value, ACOSH(value) as acosh_value
FROM VALUES (1.0), (2.0), (5.0) AS t(value);
// DataFrame API examples
import org.apache.spark.sql.functions._
// Basic computation
df.select(acosh(col("measurement")))
// With column alias
df.select(acosh(col("input")).alias("acosh_result"))
// Combined with other expressions
df.select(col("id"), acosh(col("value") + 1))
See Also¶
Asinh- Inverse hyperbolic sine functionAtanh- Inverse hyperbolic tangent functionCosh- Hyperbolic cosine functionLog- Natural logarithm functionSqrt- Square root function