Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

std.math.trigonometry

This is a submodule ofstd.math.
It contains several trigonometric functions.
License:
Boost License 1.0.
Authors:
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger

Sourcestd/math/trigonometry.d

pure nothrow @nogc @safe realcos(realx);

pure nothrow @nogc @safe doublecos(doublex);

pure nothrow @nogc @safe floatcos(floatx);
Returns cosine of x. x is in radians.
Special Values
xcos(x)invalid?
NANNANyes
±∞NANyes
Bugs:
Results are undefined if |x| >= 264.
Examples:
import std.math.operations : isClose;writeln(cos(0.0));// 1.0assert(cos(1.0).isClose(0.5403023059));assert(cos(3.0).isClose(-0.9899924966));
pure nothrow @nogc @safe realsin(realx);

pure nothrow @nogc @safe doublesin(doublex);

pure nothrow @nogc @safe floatsin(floatx);
Returnssine of x. x is inradians.
Special Values
x sin(x) invalid?
NANNAN yes
±0.0 ±0.0 no
±∞NAN yes
Parameters:
realxangle in radians (not degrees)
Returns:
sine of x
See Also:
cos ,tan ,asin 
Bugs:
Results are undefined if |x| >= 264.
Examples:
import std.math.constants : PI;import std.stdio : writefln;void someFunc(){realx = 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 realtan(realx);

pure nothrow @nogc @safe doubletan(doublex);

pure nothrow @nogc @safe floattan(floatx);
Returns tangent of x. x is in radians.
Special Values
xtan(x)invalid?
NANNANyes
±0.0±0.0no
±∞NANyes
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 realacos(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
xacos(x)invalid?
>1.0NANyes
<-1.0NANyes
NANNANyes
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 realasin(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
xasin(x)invalid?
±0.0±0.0no
>1.0NANyes
<-1.0NANyes
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 realatan(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
xatan(x)invalid?
±0.0±0.0no
±∞NANyes
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 realatan2(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
yxatan(y, x)
NANanythingNAN
anythingNANNAN
±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 realcosh(realx);

pure nothrow @nogc @safe doublecosh(doublex);

pure nothrow @nogc @safe floatcosh(floatx);
Calculates the hyperbolic cosine of x.
Special Values
xcosh(x)invalid?
±∞±0.0no
Examples:
import std.math.constants : E;import std.math.operations : isClose;writeln(cosh(0.0));// 1.0assert(cosh(1.0).isClose((E + 1.0 / E) / 2));
pure nothrow @nogc @safe realsinh(realx);

pure nothrow @nogc @safe doublesinh(doublex);

pure nothrow @nogc @safe floatsinh(floatx);
Calculates the hyperbolic sine of x.
Special Values
xsinh(x)invalid?
±0.0±0.0no
±∞±∞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;staticforeach (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 realtanh(realx);

pure nothrow @nogc @safe doubletanh(doublex);

pure nothrow @nogc @safe floattanh(floatx);
Calculates the hyperbolic tangent of x.
Special Values
xtanh(x)invalid?
±0.0±0.0no
±∞±1.0no
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 realacosh(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 XRange Y
1..∞ 0..∞
Special Values
x acosh(x)
NANNAN
<1NAN
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.infinityassert(isNaN(acosh(0.5)));
pure nothrow @nogc @safe realasinh(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 >= +0asinh(x) = -log(-x + sqrt(x*x + 1 ))// if x <= -0
Special Values
x asinh(x)
NANNAN
±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.infinitywriteln(asinh(-real.infinity));// -real.infinityassert(isNaN(asinh(real.nan)));
pure nothrow @nogc @safe realatanh(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 XRange Y
-∞..∞ -1 .. 1

Special Values
x acosh(x)
NANNAN
±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-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 17:59:21 2026

[8]ページ先頭

©2009-2026 Movatter.jp