45.2 Transcendental Functions

Understand transcendental function behavior and implement custom variants when needed.


45.2.1 Exponential Functions

// e^x
double exp = Math.exp(1.0);       // e

// e^x - 1 (accurate for small x)
double expm1 = Math.expm1(1e-10); // avoids catastrophic cancellation

// 2^x via exp
double pow2 = Math.pow(2, 10);    // or Math.exp(10 * Math.log(2))

45.2.2 Logarithmic Functions

// Natural log
double ln = Math.log(Math.E);     // 1.0

// log(1 + x) (accurate for small x)
double log1p = Math.log1p(1e-10);

// Base conversion
double log2 = Math.log(x) / Math.log(2);
double logN = Math.log(x) / Math.log(base);

45.2.3 Trigonometric Functions

// Always work in radians
double deg2rad = degrees * Math.PI / 180.0;
double rad2deg = radians * 180.0 / Math.PI;

// Range reduction for large arguments
double largeSin = Math.sin(1e10); // may lose precision

// Argument normalization
double normalized = Math.IEEEremainder(angle, 2 * Math.PI);

45.2.4 Hyperbolic Functions

// Definition
double sinh = (Math.exp(x) - Math.exp(-x)) / 2;
double cosh = (Math.exp(x) + Math.exp(-x)) / 2;

// Built-in (more accurate)
double sinh2 = Math.sinh(x);
double cosh2 = Math.cosh(x);

// Inverse hyperbolic
double asinh = Math.log(x + Math.sqrt(x*x + 1));
double acosh = Math.log(x + Math.sqrt(x*x - 1)); // x >= 1