Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions std/complex.d
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,6 @@ Complex!(CommonType!(T, U)) fromPolar(T, U)(T modulus, U argument)
*/
Complex!T sin(T)(Complex!T z) @safe pure nothrow @nogc
{
import std.math : expi, coshisinh;
auto cs = expi(z.re);
auto csh = coshisinh(z.im);
return typeof(return)(cs.im * csh.re, cs.re * csh.im);
Expand All @@ -840,7 +839,6 @@ Complex!T sin(T)(Complex!T z) @safe pure nothrow @nogc
/// ditto
Complex!T cos(T)(Complex!T z) @safe pure nothrow @nogc
{
import std.math : expi, coshisinh;
auto cs = expi(z.re);
auto csh = coshisinh(z.im);
return typeof(return)(cs.re * csh.re, - cs.im * csh.im);
Expand Down Expand Up @@ -886,6 +884,39 @@ Complex!real expi(real y) @trusted pure nothrow @nogc
}


/**
Params: y = A real number.
Returns: The value of cosh(y) + i sinh(y)

Note:
$(D coshisinh) is included here for convenience and for easy migration of code
that uses $(REF _coshisinh, std,math).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the motivation behind the move?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we deprecating complex real?

*/
Complex!real coshisinh(real y) @safe pure nothrow @nogc
{
static import std.math;
if (std.math.fabs(y) <= 0.5)
return Complex!real(std.math.cosh(y), std.math.sinh(y));
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant control flow

{
auto z = std.math.exp(y);
auto zi = 0.5 / z;
z = 0.5 * z;
return Complex!real(z + zi, z - zi);
}
}

@safe pure nothrow @nogc unittest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making this a publicly documented example?

{
static import std.math;

assert(coshisinh(3.0L) == complex(std.math.cosh(3.0L), std.math.sinh(3.0L)));
auto z1 = coshisinh(1.234);
auto z2 = std.math.coshisinh(1.234);
assert(z1.re == z2.re && z1.im == z2.im);
}


/**
Params: z = A complex number.
Returns: The square root of `z`.
Expand Down