Skip to content

HMath.Trigonometry

Module index · Numerical conventions

Description

Radian-based checked trigonometry. Real inverse branches: asin [-pi2,pi2], acos [0,pi], atan (-pi2,pi2), acot (0,pi). Nonfinite inputs and undefined real domains return errors. Poles at represented multiples of pi and pi/2 are rejected; near poles remain finite when representable. Complex functions use the principal branches of Data.Complex (NIST DLMF sections 4.23 and 4.37).

On this page

API Purpose
sinChecked Sine of a radian argument.
cosChecked Cosine of a radian argument.
tanChecked Tangent of a radian argument; represented poles at odd pi/2 are rejected.
asinChecked Principal inverse sine in [-pi2,pi2]; require abs(x)<=1.
acosChecked Principal inverse cosine in [0,pi]; require abs(x)<=1.
atanChecked Principal inverse tangent in (-pi2,pi2).
atan2Checked Conventional atan2(y,x), range [-pi,pi].
sec Secant 1cos(x) in radians; represented odd-pi2 poles fail.
csc Cosecant 1/sin(x) in radians; represented multiples of pi fail.
cot Cotangent cos(x)/sin(x) in radians; represented multiples of pi fail.
asec Principal inverse secant acos(1/x); require abs(x)>=1.
acsc Principal inverse cosecant asin(1/x); require abs(x)>=1.
acot Inverse cotangent atan2(1,x), with range (0,pi).
sinhChecked Hyperbolic sine.
coshChecked Hyperbolic cosine.
tanhChecked Hyperbolic tangent.
asinhChecked Inverse hyperbolic sine.
acoshChecked Principal real inverse hyperbolic cosine; require x>=1.
atanhChecked Inverse hyperbolic tangent; require abs(x)<1.
sech Hyperbolic secant 1/cosh(x), using a scaled exponential formula for large arguments.
csch Hyperbolic cosecant 1/sinh(x); reject zero.
coth Hyperbolic cotangent 1/tanh(x); reject zero.
asech Inverse hyperbolic secant; require 0<x<=1.
acsch Inverse hyperbolic cosecant; reject zero and use a log formula near zero.
acoth Inverse hyperbolic cotangent; require abs(x)>1.
sincos Given a finite radian angle, return Right (sin x,cos x), propagating checked input/result failures.
wrap Wrap to [lo,hi).
normalizeAngle Wrap a finite radian angle into [0,2*pi).
normalizeSignedAngle Wrap a finite radian angle into [-pi,pi).
angleDifference Given angles a then b, return the signed wrapped difference a-b in [-pi,pi).
versine Versine 1-cos(x), evaluated as 2*sin(x/2)^2 for a radian input.
haversine Haversine sin(x/2)^2 for a radian input.
sinc Unnormalized sinc sin(x)/x for radians, with continuous value 1 at zero.
cosc (1-cos x)/x with its continuous value 0 at x=0.
greatCircleAngle Latitudes in [-pi2,pi2], longitudes any finite radians.
greatCircleDistance Given finite nonnegative sphere radius and two (latitude,longitude) radian pairs, return radius times the central angle.
sphericalSide Two spherical sides and their included angle, all in [0,pi].
sphericalAngles Interior angles for a nondegenerate minor spherical triangle, sides (0,pi).
sphericalExcess Given three side angles of a nondegenerate minor spherical triangle, compute interior-angle sum minus pi.
ComplexFunction Checked complex trigonometric/hyperbolic principal-branch function selector,including reciprocal secantcosecantcotangent variants.
CSin Declaration and type contract below.
CCos Declaration and type contract below.
CTan Declaration and type contract below.
CAsin Declaration and type contract below.
CAcos Declaration and type contract below.
CAtan Declaration and type contract below.
CSinh Declaration and type contract below.
CCosh Declaration and type contract below.
CTanh Declaration and type contract below.
CAsinh Declaration and type contract below.
CAcosh Declaration and type contract below.
CAtanh Declaration and type contract below.
CSec Declaration and type contract below.
CCsc Declaration and type contract below.
CCot Declaration and type contract below.
CSech Declaration and type contract below.
CCsch Declaration and type contract below.
CCoth Declaration and type contract below.
complexFunction Given a ComplexFunction selector then complex input, compute the selected principal-branch Data.Complex function or reciprocal.
complexSin Principal complex sine, dispatched through complexFunction.
complexCos Principal complex cosine, dispatched through complexFunction.
complexTan Principal complex tangent, dispatched through complexFunction.
complexAsin Principal complex inverse sine, dispatched through complexFunction.
complexAcos Principal complex inverse cosine, dispatched through complexFunction.
complexAtan Principal complex inverse tangent, dispatched through complexFunction.
complexSinh Principal complex hyperbolic sine, dispatched through complexFunction.
complexCosh Principal complex hyperbolic cosine, dispatched through complexFunction.
complexTanh Principal complex hyperbolic tangent, dispatched through complexFunction.
complexAsinh Principal complex inverse hyperbolic sine, dispatched through complexFunction.
complexAcosh Principal complex inverse hyperbolic cosine, dispatched through complexFunction.
complexAtanh Principal complex inverse hyperbolic tangent, dispatched through complexFunction.
periodicSawtooth Unit-amplitude periodic waves.
periodicTriangle Unit-amplitude periodic waves.
periodicSquare Unit-amplitude periodic waves.

Documentation

sinChecked

sinChecked :: RealFloat a => a -> Either MathError a Source #

Sine of a radian argument. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

cosChecked

cosChecked :: RealFloat a => a -> Either MathError a Source #

Cosine of a radian argument. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

tanChecked

tanChecked :: RealFloat a => a -> Either MathError a Source #

Tangent of a radian argument; represented poles at odd pi/2 are rejected. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

asinChecked

asinChecked :: RealFloat a => a -> Either MathError a Source #

Principal inverse sine in [-pi2,pi2]; require abs(x)<=1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

acosChecked

acosChecked :: RealFloat a => a -> Either MathError a Source #

Principal inverse cosine in [0,pi]; require abs(x)<=1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

atanChecked

atanChecked :: RealFloat a => a -> Either MathError a Source #

Principal inverse tangent in (-pi2,pi2). Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

atan2Checked

atan2Checked :: RealFloat a => a -> a -> Either MathError a Source #

Conventional atan2(y,x), range [-pi,pi]. Rejects the undefined origin.

sec

sec :: RealFloat a => a -> Either MathError a Source #

Secant 1cos(x) in radians; represented odd-pi2 poles fail. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

csc

csc :: RealFloat a => a -> Either MathError a Source #

Cosecant 1/sin(x) in radians; represented multiples of pi fail. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

cot

cot :: RealFloat a => a -> Either MathError a Source #

Cotangent cos(x)/sin(x) in radians; represented multiples of pi fail. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

asec

asec :: RealFloat a => a -> Either MathError a Source #

Principal inverse secant acos(1/x); require abs(x)>=1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

acsc

acsc :: RealFloat a => a -> Either MathError a Source #

Principal inverse cosecant asin(1/x); require abs(x)>=1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

acot

acot :: RealFloat a => a -> Either MathError a Source #

Inverse cotangent atan2(1,x), with range (0,pi). Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

sinhChecked

sinhChecked :: RealFloat a => a -> Either MathError a Source #

Hyperbolic sine. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

coshChecked

coshChecked :: RealFloat a => a -> Either MathError a Source #

Hyperbolic cosine. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

tanhChecked

tanhChecked :: RealFloat a => a -> Either MathError a Source #

Hyperbolic tangent. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

asinhChecked

asinhChecked :: RealFloat a => a -> Either MathError a Source #

Inverse hyperbolic sine. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

acoshChecked

acoshChecked :: RealFloat a => a -> Either MathError a Source #

Principal real inverse hyperbolic cosine; require x>=1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

atanhChecked

atanhChecked :: RealFloat a => a -> Either MathError a Source #

Inverse hyperbolic tangent; require abs(x)<1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

sech

sech :: RealFloat a => a -> Either MathError a Source #

Hyperbolic secant 1/cosh(x), using a scaled exponential formula for large arguments. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

csch

csch :: RealFloat a => a -> Either MathError a Source #

Hyperbolic cosecant 1/sinh(x); reject zero. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

coth

coth :: RealFloat a => a -> Either MathError a Source #

Hyperbolic cotangent 1/tanh(x); reject zero. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

asech

asech :: RealFloat a => a -> Either MathError a Source #

Inverse hyperbolic secant; require 0<x<=1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

acsch

acsch :: RealFloat a => a -> Either MathError a Source #

Inverse hyperbolic cosecant; reject zero and use a log formula near zero. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

acoth

acoth :: RealFloat a => a -> Either MathError a Source #

Inverse hyperbolic cotangent; require abs(x)>1. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

sincos

sincos :: RealFloat a => a -> Either MathError (a, a) Source #

Given a finite radian angle, return Right (sin x,cos x), propagating checked input/result failures. Example: sincos 0 == Right (0,1).

wrap

wrap :: RealFloat a => a -> a -> a -> Either MathError a Source #

Wrap to [lo,hi). Exact rational reduction avoids overflowing x-lo and preserves the interval contract even for huge finite values. The period is the represented endpoints' difference; no accuracy claim is made for reducing enormous angles modulo the mathematical irrational 2*pi.

normalizeAngle

normalizeAngle :: RealFloat a => a -> Either MathError a Source #

Wrap a finite radian angle into [0,2*pi). Non-finite input fails. Reduction uses the represented period; no exact huge-angle reduction against irrational pi is promised.

normalizeSignedAngle

normalizeSignedAngle :: RealFloat a => a -> Either MathError a Source #

Wrap a finite radian angle into [-pi,pi). Non-finite input fails. The positive endpoint pi wraps to -pi.

angleDifference

angleDifference :: RealFloat a => a -> a -> Either MathError a Source #

Given angles a then b, return the signed wrapped difference a-b in [-pi,pi). Reject non-finite input. Normalize operands first to avoid avoidable subtraction overflow.

versine

versine :: RealFloat a => a -> Either MathError a Source #

Versine 1-cos(x), evaluated as 2*sin(x/2)^2 for a radian input. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

haversine

haversine :: RealFloat a => a -> Either MathError a Source #

Haversine sin(x/2)^2 for a radian input. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

sinc

sinc :: RealFloat a => a -> Either MathError a Source #

Unnormalized sinc sin(x)/x for radians, with continuous value 1 at zero. Return Right result for finite input in the stated domain; invalid input/poles or non-finite output return Left MathError.

cosc

cosc :: RealFloat a => a -> Either MathError a Source #

(1-cos x)/x with its continuous value 0 at x=0.

greatCircleAngle

greatCircleAngle :: RealFloat a => (a, a) -> (a, a) -> Either MathError a Source #

Latitudes in [-pi2,pi2], longitudes any finite radians. Central angle [0,pi].

greatCircleDistance

greatCircleDistance :: RealFloat a => a -> (a, a) -> (a, a) -> Either MathError a Source #

Given finite nonnegative sphere radius and two (latitude,longitude) radian pairs, return radius times the central angle. Reject invalid latitude, non-finite input, or result overflow. Distance uses the radius units.

sphericalSide

sphericalSide :: RealFloat a => a -> a -> a -> Either MathError a Source #

Two spherical sides and their included angle, all in [0,pi].

sphericalAngles

sphericalAngles :: RealFloat a => a -> a -> a -> Either MathError (a, a, a) Source #

Interior angles for a nondegenerate minor spherical triangle, sides (0,pi).

sphericalExcess

sphericalExcess :: RealFloat a => a -> a -> a -> Either MathError a Source #

Given three side angles of a nondegenerate minor spherical triangle, compute interior-angle sum minus pi. Side/domain errors propagate from sphericalAngles. Multiply by radius squared for area.

ComplexFunction

data ComplexFunction Source #

Checked complex trigonometric/hyperbolic principal-branch function selector,including reciprocal secantcosecantcotangent variants.

complexFunction

complexFunction :: RealFloat a => ComplexFunction -> Complex a -> Either MathError (Complex a) Source #

Given a ComplexFunction selector then complex input, compute the selected principal-branch Data.Complex function or reciprocal. Reject non-finite components and non-finite results/poles with Left DomainError.

complexSin

complexSin :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex sine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexCos

complexCos :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex cosine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexTan

complexTan :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex tangent, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexAsin

complexAsin :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex inverse sine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexAcos

complexAcos :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex inverse cosine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexAtan

complexAtan :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex inverse tangent, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexSinh

complexSinh :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex hyperbolic sine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexCosh

complexCosh :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex hyperbolic cosine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexTanh

complexTanh :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex hyperbolic tangent, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexAsinh

complexAsinh :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex inverse hyperbolic sine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexAcosh

complexAcosh :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex inverse hyperbolic cosine, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

complexAtanh

complexAtanh :: RealFloat a => Complex a -> Either MathError (Complex a) Source #

Principal complex inverse hyperbolic tangent, dispatched through complexFunction. Return Right complex result; non-finite input components or a pole/overflow producing non-finite components return Left DomainError. Angles use radians.

periodicSawtooth

periodicSawtooth :: RealFloat a => a -> a -> Either MathError a Source #

Unit-amplitude periodic waves. Period must be positive and finite. Square wave is +1 on the first half-cycle, -1 on the second, including midpoint.

periodicTriangle

periodicTriangle :: RealFloat a => a -> a -> Either MathError a Source #

Unit-amplitude periodic waves. Period must be positive and finite. Square wave is +1 on the first half-cycle, -1 on the second, including midpoint.

periodicSquare

periodicSquare :: RealFloat a => a -> a -> Either MathError a Source #

Unit-amplitude periodic waves. Period must be positive and finite. Square wave is +1 on the first half-cycle, -1 on the second, including midpoint.