Complete trigonometric and hyperbolic function suite including sine, cosine, tangent and their inverse functions. All functions work with radians and provide arbitrary precision calculations.
Standard trigonometric functions for sine, cosine, and tangent.
/**
* Return a new Decimal whose value is the sine of this Decimal (in radians)
* @returns New Decimal instance with sin(x)
*/
sine(): Decimal;
sin(): Decimal; // Alias for sine
/**
* Return a new Decimal whose value is the cosine of this Decimal (in radians)
* @returns New Decimal instance with cos(x)
*/
cosine(): Decimal;
cos(): Decimal; // Alias for cosine
/**
* Return a new Decimal whose value is the tangent of this Decimal (in radians)
* @returns New Decimal instance with tan(x)
*/
tangent(): Decimal;
tan(): Decimal; // Alias for tangent
// Static versions
static sin(n: Decimal.Value): Decimal;
static cos(n: Decimal.Value): Decimal;
static tan(n: Decimal.Value): Decimal;Usage Examples:
import Decimal from "decimal.js";
// Basic trigonometric calculations
const pi = new Decimal('3.1415926535897932384626433832795');
const halfPi = pi.div('2');
const sinHalfPi = halfPi.sin(); // '1'
const cosZero = new Decimal('0').cos(); // '1'
const tanZero = new Decimal('0').tan(); // '0'
// Static usage
const sin30 = Decimal.sin(pi.div('6')); // '0.5' (sin(π/6))
const cos60 = Decimal.cos(pi.div('3')); // '0.5' (cos(π/3))Inverse trigonometric functions returning angles in radians.
/**
* Return a new Decimal whose value is the arcsine (inverse sine) of this Decimal
* @returns New Decimal instance with asin(x) in radians
*/
inverseSine(): Decimal;
asin(): Decimal; // Alias for inverseSine
/**
* Return a new Decimal whose value is the arccosine (inverse cosine) of this Decimal
* @returns New Decimal instance with acos(x) in radians
*/
inverseCosine(): Decimal;
acos(): Decimal; // Alias for inverseCosine
/**
* Return a new Decimal whose value is the arctangent (inverse tangent) of this Decimal
* @returns New Decimal instance with atan(x) in radians
*/
inverseTangent(): Decimal;
atan(): Decimal; // Alias for inverseTangent
// Static versions
static asin(n: Decimal.Value): Decimal;
static acos(n: Decimal.Value): Decimal;
static atan(n: Decimal.Value): Decimal;Usage Examples:
// Inverse trigonometric calculations
const one = new Decimal('1');
const half = new Decimal('0.5');
const asinOne = one.asin(); // '1.5707963267948966192' (π/2)
const acosHalf = half.acos(); // '1.0471975511965977462' (π/3)
const atanOne = one.atan(); // '0.78539816339744830962' (π/4)
// Static usage
const result = Decimal.asin('0.5'); // '0.52359877559829887308' (π/6)Calculate arctangent of y/x using the signs of both arguments to determine the quadrant.
/**
* Return a new Decimal whose value is the arctangent of y/x in radians
* Uses the signs of y and x to determine the quadrant
* @param y - The y coordinate
* @param x - The x coordinate
* @returns New Decimal instance with atan2(y,x) in radians
*/
static atan2(y: Decimal.Value, x: Decimal.Value): Decimal;Usage Examples:
// Calculate angle from origin to point (3, 4)
const angle = Decimal.atan2('4', '3'); // '0.92729521800161223243'
// Quadrant determination
const q1 = Decimal.atan2('1', '1'); // '0.78539816339744830962' (π/4, first quadrant)
const q2 = Decimal.atan2('1', '-1'); // '2.3561944901923449288' (3π/4, second quadrant)
const q3 = Decimal.atan2('-1', '-1'); // '-2.3561944901923449288' (-3π/4, third quadrant)
const q4 = Decimal.atan2('-1', '1'); // '-0.78539816339744830962' (-π/4, fourth quadrant)Hyperbolic functions for sinh, cosh, and tanh.
/**
* Return a new Decimal whose value is the hyperbolic sine of this Decimal
* @returns New Decimal instance with sinh(x)
*/
hyperbolicSine(): Decimal;
sinh(): Decimal; // Alias for hyperbolicSine
/**
* Return a new Decimal whose value is the hyperbolic cosine of this Decimal
* @returns New Decimal instance with cosh(x)
*/
hyperbolicCosine(): Decimal;
cosh(): Decimal; // Alias for hyperbolicCosine
/**
* Return a new Decimal whose value is the hyperbolic tangent of this Decimal
* @returns New Decimal instance with tanh(x)
*/
hyperbolicTangent(): Decimal;
tanh(): Decimal; // Alias for hyperbolicTangent
// Static versions
static sinh(n: Decimal.Value): Decimal;
static cosh(n: Decimal.Value): Decimal;
static tanh(n: Decimal.Value): Decimal;Usage Examples:
// Hyperbolic function calculations
const one = new Decimal('1');
const zero = new Decimal('0');
const sinhOne = one.sinh(); // '1.1752011936438014569'
const coshZero = zero.cosh(); // '1'
const tanhOne = one.tanh(); // '0.76159415595576488812'
// Relationship: cosh²(x) - sinh²(x) = 1
const x = new Decimal('2');
const coshX = x.cosh();
const sinhX = x.sinh();
const identity = coshX.pow('2').minus(sinhX.pow('2')); // '1'Inverse hyperbolic functions for asinh, acosh, and atanh.
/**
* Return a new Decimal whose value is the inverse hyperbolic sine of this Decimal
* @returns New Decimal instance with asinh(x)
*/
inverseHyperbolicSine(): Decimal;
asinh(): Decimal; // Alias for inverseHyperbolicSine
/**
* Return a new Decimal whose value is the inverse hyperbolic cosine of this Decimal
* @returns New Decimal instance with acosh(x)
*/
inverseHyperbolicCosine(): Decimal;
acosh(): Decimal; // Alias for inverseHyperbolicCosine
/**
* Return a new Decimal whose value is the inverse hyperbolic tangent of this Decimal
* @returns New Decimal instance with atanh(x)
*/
inverseHyperbolicTangent(): Decimal;
atanh(): Decimal; // Alias for inverseHyperbolicTangent
// Static versions
static asinh(n: Decimal.Value): Decimal;
static acosh(n: Decimal.Value): Decimal;
static atanh(n: Decimal.Value): Decimal;Usage Examples:
// Inverse hyperbolic function calculations
const value = new Decimal('1.1752011936438014569');
const asinhResult = value.asinh(); // Should be close to '1'
const coshValue = new Decimal('1.5430806348152437785');
const acoshResult = coshValue.acosh(); // Should be close to '1'
const halfTanh = new Decimal('0.5');
const atanhHalf = halfTanh.atanh(); // '0.54930614433405484570'
// Domain considerations
// acosh(x) requires x >= 1
// atanh(x) requires -1 < x < 1The trigonometric and hyperbolic functions maintain their mathematical relationships:
Trigonometric Identities:
Hyperbolic Identities:
Usage Examples:
// Verify trigonometric identity: sin²(x) + cos²(x) = 1
const angle = new Decimal('0.5');
const sinAngle = angle.sin();
const cosAngle = angle.cos();
const identity = sinAngle.pow('2').plus(cosAngle.pow('2')); // Should be '1'
// Verify hyperbolic identity: cosh²(x) - sinh²(x) = 1
const x = new Decimal('1.5');
const coshX = x.cosh();
const sinhX = x.sinh();
const hyperbolicIdentity = coshX.pow('2').minus(sinhX.pow('2')); // Should be '1'
// Calculate tan using sin and cos
const tanFromRatio = sinAngle.div(cosAngle);
const tanDirect = angle.tan();
// tanFromRatio should equal tanDirect