Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
std.math.trigonometry
This is a submodule of std.math.
It contains several trigonometric functions.
License:
Authors:
Walter Bright, Don Clugston,
Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
Source std/math/trigonometry.d
- pure nothrow @nogc @safe real
cos
(realx
);
pure nothrow @nogc @safe doublecos
(doublex
);
pure nothrow @nogc @safe floatcos
(floatx
); - Returns cosine of x. x is in radians.
Special Values x cos(x) invalid? NAN NAN yes ±∞ NAN yes Bugs:Results are undefined if |x| >= 264.Examples:import std.math.operations : isClose; writeln(cos(0.0)); // 1.0 assert(cos(1.0).isClose(0.5403023059)); assert(cos(3.0).isClose(-0.9899924966));
- pure nothrow @nogc @safe real
sin
(realx
);
pure nothrow @nogc @safe doublesin
(doublex
);
pure nothrow @nogc @safe floatsin
(floatx
); Special Values x sin(x) invalid? NAN NAN yes ±0.0 ±0.0 no ±∞ NAN yes Parameters:real x
angle in radians (not degrees) Returns:sine of xBugs:Results are undefined if |x| >= 264.Examples:import std.math.constants : PI; import std.stdio : writefln; void someFunc() { real x = 30.0; auto result = sin(x * (PI / 180)); // convert degrees to radians writefln("The sine of %s degrees is %s", x, result); }
- pure nothrow @nogc @safe real
tan
(realx
);
pure nothrow @nogc @safe doubletan
(doublex
);
pure nothrow @nogc @safe floattan
(floatx
); - Returns tangent of x. x is in radians.
Special Values x tan(x) invalid? NAN NAN yes ±0.0 ±0.0 no ±∞ NAN yes Examples:import std.math.operations : isClose; import std.math.traits : isIdentical; import std.math.constants : PI; import std.math.algebraic : sqrt; assert(isIdentical(tan(0.0), 0.0)); assert(tan(PI).isClose(0, 0.0, 1e-10)); assert(tan(PI / 3).isClose(sqrt(3.0)));
- pure nothrow @nogc @safe real
acos
(realx
);
pure nothrow @nogc @safe doubleacos
(doublex
);
pure nothrow @nogc @safe floatacos
(floatx
); - Calculates the arc cosine of x, returning a value ranging from 0 to π.
Special Values x acos(x) invalid? >1.0 NAN yes <-1.0 NAN yes NAN NAN yes Examples:import std.math.operations : isClose; import std.math.traits : isNaN; import std.math.constants : PI; assert(acos(0.0).isClose(1.570796327)); assert(acos(0.5).isClose(PI / 3)); assert(acos(PI).isNaN);
- pure nothrow @nogc @safe real
asin
(realx
);
pure nothrow @nogc @safe doubleasin
(doublex
);
pure nothrow @nogc @safe floatasin
(floatx
); - Calculates the arc sine of x, returning a value ranging from -π/2 to π/2.
Special Values x asin(x) invalid? ±0.0 ±0.0 no >1.0 NAN yes <-1.0 NAN yes Examples:import std.math.operations : isClose; import std.math.traits : isIdentical, isNaN; import std.math.constants : PI; assert(isIdentical(asin(0.0), 0.0)); assert(asin(0.5).isClose(PI / 6)); assert(asin(PI).isNaN);
- pure nothrow @nogc @safe real
atan
(realx
);
pure nothrow @nogc @safe doubleatan
(doublex
);
pure nothrow @nogc @safe floatatan
(floatx
); - Calculates the arc tangent of x, returning a value ranging from -π/2 to π/2.
Special Values x atan(x) invalid? ±0.0 ±0.0 no ±∞ NAN yes Examples:import std.math.operations : isClose; import std.math.traits : isIdentical; import std.math.constants : PI; import std.math.algebraic : sqrt; assert(isIdentical(atan(0.0), 0.0)); assert(atan(sqrt(3.0)).isClose(PI / 3));
- pure nothrow @nogc @trusted real
atan2
(realy
, realx
);
pure nothrow @nogc @safe doubleatan2
(doubley
, doublex
);
pure nothrow @nogc @safe floatatan2
(floaty
, floatx
); - Calculates the arc tangent of y / x, returning a value ranging from -π to π.
Special Values y x atan(y, x) NAN anything NAN anything NAN NAN ±0.0 >0.0 ±0.0 ±0.0 +0.0 ±0.0 ±0.0 <0.0 ±π ±0.0 -0.0 ±π >0.0 ±0.0 π/2 <0.0 ±0.0 -π/2 >0.0 ∞ ±0.0 ±∞ anything ±π/2 >0.0 -∞ ±π ±∞ ∞ ±π/4 ±∞ -∞ ±3π/4 Examples:import std.math.operations : isClose; import std.math.constants : PI; import std.math.algebraic : sqrt; assert(atan2(1.0, sqrt(3.0)).isClose(PI / 6));
- pure nothrow @nogc @safe real
cosh
(realx
);
pure nothrow @nogc @safe doublecosh
(doublex
);
pure nothrow @nogc @safe floatcosh
(floatx
); - Calculates the hyperbolic cosine of x.
Special Values x cosh(x) invalid? ±∞ ±0.0 no Examples:import std.math.constants : E; import std.math.operations : isClose; writeln(cosh(0.0)); // 1.0 assert(cosh(1.0).isClose((E + 1.0 / E) / 2));
- pure nothrow @nogc @safe real
sinh
(realx
);
pure nothrow @nogc @safe doublesinh
(doublex
);
pure nothrow @nogc @safe floatsinh
(floatx
); - Calculates the hyperbolic sine of x.
Special Values x sinh(x) invalid? ±0.0 ±0.0 no ±∞ ±∞ no Examples:import std.math.constants : E; import std.math.operations : isClose; import std.math.traits : isIdentical; enum sinh1 = (E - 1.0 / E) / 2; import std.meta : AliasSeq; static foreach (F; AliasSeq!(float, double, real)) { assert(isIdentical(sinh(F(0.0)), F(0.0))); assert(sinh(F(1.0)).isClose(F(sinh1))); }
- pure nothrow @nogc @safe real
tanh
(realx
);
pure nothrow @nogc @safe doubletanh
(doublex
);
pure nothrow @nogc @safe floattanh
(floatx
); - Calculates the hyperbolic tangent of x.
Special Values x tanh(x) invalid? ±0.0 ±0.0 no ±∞ ±1.0 no Examples:import std.math.operations : isClose; import std.math.traits : isIdentical; assert(isIdentical(tanh(0.0), 0.0)); assert(tanh(1.0).isClose(sinh(1.0) / cosh(1.0)));
- pure nothrow @nogc @safe real
acosh
(realx
);
pure nothrow @nogc @safe doubleacosh
(doublex
);
pure nothrow @nogc @safe floatacosh
(floatx
); - Calculates the inverse hyperbolic cosine of x.Mathematically, acosh(x) = log(x + sqrt( x*x - 1))
Domain X Range Y 1..∞ 0..∞ Special Values x acosh(x) NAN NAN <1 NAN 1 0 +∞ +∞ Examples:import std.math.traits : isIdentical, isNaN; assert(isNaN(acosh(0.9))); assert(isNaN(acosh(real.nan))); assert(isIdentical(acosh(1.0), 0.0)); writeln(acosh(real.infinity)); // real.infinity assert(isNaN(acosh(0.5)));
- pure nothrow @nogc @safe real
asinh
(realx
);
pure nothrow @nogc @safe doubleasinh
(doublex
);
pure nothrow @nogc @safe floatasinh
(floatx
); - Calculates the inverse hyperbolic sine of x.Mathematically,
asinh(x) = log( x + sqrt( x*x + 1 )) // if x >= +0 asinh(x) = -log(-x + sqrt( x*x + 1 )) // if x <= -0
Special Values x asinh(x) NAN NAN ±0 ±0 ±∞ ±∞ Examples:import std.math.traits : isIdentical, isNaN; assert(isIdentical(asinh(0.0), 0.0)); assert(isIdentical(asinh(-0.0), -0.0)); writeln(asinh(real.infinity)); // real.infinity writeln(asinh(-real.infinity)); // -real.infinity assert(isNaN(asinh(real.nan)));
- pure nothrow @nogc @safe real
atanh
(realx
);
pure nothrow @nogc @safe doubleatanh
(doublex
);
pure nothrow @nogc @safe floatatanh
(floatx
); - Calculates the inverse hyperbolic tangent of x, returning a value from ranging from -1 to 1.Mathematically, atanh(x) = log( (1+x)/(1-x) ) / 2
Domain X Range Y -∞..∞ -1 .. 1
Special Values x acosh(x) NAN NAN ±0 ±0 -∞ -0 Examples:import std.math.traits : isIdentical, isNaN; assert(isIdentical(atanh(0.0), 0.0)); assert(isIdentical(atanh(-0.0),-0.0)); assert(isNaN(atanh(real.nan))); assert(isNaN(atanh(-real.infinity))); writeln(atanh(0.0)); // 0
Copyright © 1999-2024 by the D Language Foundation | Page generated by
Ddoc on Wed Dec 18 08:54:23 2024