Expand Up
@@ -49,9 +49,6 @@ $(TR $(TDNW Introspection) $(TD
$(MYREF isNormal) $(MYREF isSubnormal) $(MYREF signbit) $(MYREF sgn)
$(MYREF copysign) $(MYREF isPowerOf2)
))
$(TR $(TDNW Complex Numbers) $(TD
$(MYREF abs) $(MYREF conj) $(MYREF sin) $(MYREF cos) $(MYREF expi)
))
$(TR $(TDNW Hardware Control) $(TD
$(MYREF IeeeFlags) $(MYREF FloatingPointControl)
))
Expand Down
Expand Up
@@ -507,30 +504,53 @@ enum real SQRT2 = 0x1.6a09e667f3bcc908b2fb1366ea958p+0L; /** $(SQRT)2 = 1.4
enum real SQRT1_2 = SQRT2 / 2 ; /* * $(SQRT)$(HALF) = 0.707106... */
// Note: Make sure the magic numbers in compiler backend for x87 match these.
// it's quite tricky check for a type who will trigger a deprecation when accessed
template isDeprecatedComplex (T)
{
static if (__traits(isDeprecated, T))
{
enum isDeprecatedComplex = true ;
}
else
{
enum m = T.mangleof;
// cfloat, cdouble, creal
// ifloat, idouble, ireal
enum isDeprecatedComplex = m == " q" || m == " r" || m == " c" ||
m == " o" || m == " p" || m == " j" ;
}
}
deprecated unittest
{
static assert (isDeprecatedComplex! cfloat );
static assert (isDeprecatedComplex! cdouble );
static assert (isDeprecatedComplex! creal );
static assert (isDeprecatedComplex! ifloat );
static assert (isDeprecatedComplex! idouble );
static assert (isDeprecatedComplex! ireal );
static assert (! isDeprecatedComplex! float );
static assert (! isDeprecatedComplex! double );
static assert (! isDeprecatedComplex! real );
}
/* **********************************
* Calculates the absolute value of a number
*
* Params:
* Num = (template parameter) type of number
* x = real number value
* z = complex number value
* y = imaginary number value
*
* Returns:
* The absolute value of the number. If floating-point or integral,
* the return type will be the same as the input; if complex or
* imaginary, the returned value will be the corresponding floating
* point type.
*
* For complex numbers, abs(z) = sqrt( $(POWER z.re, 2) + $(POWER z.im, 2) )
* = hypot(z.re, z.im).
* the return type will be the same as the input;
*/
Num abs (Num)(Num x) @safe pure nothrow
if (( is ( typeof (Num.init >= 0 )) && is ( typeof ( - Num.init)) ||
( is ( Num == short ) || is (Num == byte ))) &&
! (is (Num* : const ( ifloat * )) || is (Num * : const ( idouble * ))
|| is (Num* : const ( ireal * ))))
auto abs (Num)(Num x)
// workaround for https://issues.dlang.org/show_bug.cgi?id=18251
// if (!isDeprecatedComplex! Num &&
// (is(typeof( Num.init >= 0 )) && is(typeof(-Num.init)) ||
// (is(Num == short) || is(Num == byte ))))
{
static if (isFloatingPoint! (Num))
return fabs (x);
Expand All
@@ -543,20 +563,22 @@ if ((is(typeof(Num.init >= 0)) && is(typeof(-Num.init)) ||
}
}
// / ditto
auto abs (Num)(Num z) @safe pure nothrow @nogc
if (is (Num* : const (cfloat * )) || is (Num* : const (cdouble * ))
|| is (Num* : const (creal * )))
import std.meta : AliasSeq;
deprecated (" Please use std.complex" )
static foreach (Num; AliasSeq! (cfloat , cdouble , creal , ifloat , idouble , ireal ))
{
return hypot (z.re, z.im);
}
// / ditto
auto abs (Num)(Num y) @safe pure nothrow @nogc
if (is (Num* : const (ifloat * )) || is (Num* : const (idouble * ))
|| is (Num* : const (ireal * )))
{
return fabs (y.im);
auto abs (Num z) @safe pure nothrow @nogc
{
enum m = Num.mangleof;
// cfloat, cdouble, creal
static if (m == " q" || m == " r" || m == " c" )
return hypot (z.re, z.im);
// ifloat, idouble, ireal
else static if (m == " o" || m == " p" || m == " j" )
return fabs (z.im);
else
static assert (0 , " Unsupported type: " ~ Num.stringof);
}
}
// / ditto
Expand All
@@ -565,10 +587,15 @@ if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
assert (isIdentical(abs(- 0.0L ), 0.0L ));
assert (isNaN(abs(real .nan)));
assert (abs(- real .infinity) == real .infinity);
assert (abs(- 3. 2Li) == 3.2L );
assert (abs(71. 6Li) == 71.6L );
assert (abs(- 56 ) == 56 );
assert (abs(2321312L ) == 2321312L );
}
deprecated
@safe pure nothrow @nogc unittest
{
assert (abs(- 3. 2Li) == 3.2L );
assert (abs(71. 6Li) == 71.6L );
assert (abs(- 1L + 1i) == sqrt(2.0L ));
}
Expand All
@@ -589,6 +616,12 @@ if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
assert (abs(f) == f);
assert (abs(- f) == f);
}}
}
deprecated
@safe pure nothrow @nogc unittest
{
import std.meta : AliasSeq;
static foreach (T; AliasSeq! (cfloat , cdouble , creal ))
{{
T f = - 12 + 3i;
Expand All
@@ -597,14 +630,15 @@ if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
}}
}
/* **********************************
/*
* Complex conjugate
*
* conj(x + iy) = x - iy
*
* Note that z * conj(z) = $(POWER z.re, 2) - $(POWER z.im, 2)
* is always a real number
*/
deprecated (" Please use std.complex.conj" )
auto conj (Num)(Num z) @safe pure nothrow @nogc
if (is (Num* : const (cfloat * )) || is (Num* : const (cdouble * ))
|| is (Num* : const (creal * )))
Expand All
@@ -617,15 +651,15 @@ if (is(Num* : const(cfloat*)) || is(Num* : const(cdouble*))
return z.re - z.im* 1fi;
}
/* * ditto */
deprecated ( " Please use std.complex.conj " )
auto conj (Num)(Num y) @safe pure nothrow @nogc
if (is (Num* : const (ifloat * )) || is (Num* : const (idouble * ))
|| is (Num* : const (ireal * )))
{
return - y;
}
// /
deprecated
@safe pure nothrow @nogc unittest
{
creal c = 7 + 3Li;
Expand All
@@ -634,6 +668,7 @@ if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
assert (conj(z) == - z);
}
// Issue 14206
deprecated
@safe pure nothrow @nogc unittest
{
cdouble c = 7 + 3i;
Expand All
@@ -642,6 +677,7 @@ if (is(Num* : const(ifloat*)) || is(Num* : const(idouble*))
assert (conj(z) == - z);
}
// Issue 14206
deprecated
@safe pure nothrow @nogc unittest
{
cfloat c = 7f + 3fi;
Expand Down
Expand Up
@@ -724,53 +760,57 @@ float sin(float x) @safe pure nothrow @nogc { return sin(cast(real) x); }
assert (psin != null );
}
/* **********************************
/*
* Returns sine for complex and imaginary arguments.
*
* sin(z) = sin(z.re)*cosh(z.im) + cos(z.re)*sinh(z.im)i
*
* If both sin($(THETA)) and cos($(THETA)) are required,
* it is most efficient to use expi($(THETA)).
*/
creal sin (creal z) @safe pure nothrow @nogc
deprecated (" Use std.complex.sin" )
auto sin (creal z) @safe pure nothrow @nogc
{
const creal cs = expi(z.re);
const creal csh = coshisinh(z.im);
return cs.im * csh.re + cs.re * csh.im * 1i;
}
/* * ditto */
ireal sin (ireal y) @safe pure nothrow @nogc
/* ditto */
deprecated (" Use std.complex.sin" )
auto sin (ireal y) @safe pure nothrow @nogc
{
return cosh (y.im)* 1i;
}
// /
deprecated
@safe pure nothrow @nogc unittest
{
assert (sin(0.0 + 0. 0i) == 0.0 );
assert (sin(2.0 + 0. 0i) == sin(2.0L ) );
}
/* **********************************
/*
* cosine, complex and imaginary
*
* cos(z) = cos(z.re)*cosh(z.im) - sin(z.re)*sinh(z.im)i
*/
creal cos (creal z) @safe pure nothrow @nogc
deprecated (" Use std.complex.cos" )
auto cos (creal z) @safe pure nothrow @nogc
{
const creal cs = expi(z.re);
const creal csh = coshisinh(z.im);
return cs.re * csh.re - cs.im * csh.im * 1i;
}
/* * ditto */
/* ditto */
deprecated (" Use std.complex.cos" )
real cos (ireal y) @safe pure nothrow @nogc
{
return cosh (y.im);
}
// /
deprecated
@safe pure nothrow @nogc unittest
{
assert (cos(0.0 + 0. 0i)== 1.0 );
Expand Down
Expand Up
@@ -1416,7 +1456,8 @@ package:
/* Returns cosh(x) + I * sinh(x)
* Only one call to exp() is performed.
*/
creal coshisinh (real x) @safe pure nothrow @nogc
deprecated (" Use std.complex" )
auto coshisinh (real x) @safe pure nothrow @nogc
{
// See comments for cosh, sinh.
if (fabs(x) > real .mant_dig * LN2 )
Expand All
@@ -1431,6 +1472,7 @@ creal coshisinh(real x) @safe pure nothrow @nogc
}
}
deprecated
@safe pure nothrow @nogc unittest
{
creal c = coshisinh(3.0L );
Expand Down
Expand Up
@@ -1633,7 +1675,8 @@ real sqrt(real x) @nogc @safe pure nothrow { pragma(inline, true); return core.m
assert (psqrtr != null );
}
creal sqrt (creal z) @nogc @safe pure nothrow
deprecated (" Use std.complex.sqrt" )
auto sqrt (creal z) @nogc @safe pure nothrow
{
creal c;
real x,y,w,r;
Expand Down
Expand Up
@@ -2538,13 +2581,14 @@ private real exp2Impl(real x) @nogc @trusted pure nothrow
}
/**
/*
* Calculate cos(y) + i sin(y).
*
* On many CPUs (such as x86), this is a very efficient operation;
* almost twice as fast as calculating sin(y) and cos(y) separately,
* and is the preferred method when both are required.
*/
deprecated (" Use std.complex.expi" )
creal expi (real y) @trusted pure nothrow @nogc
{
version (InlineAsm_X86_Any)
Expand Down
Expand Up
@@ -2576,7 +2620,7 @@ creal expi(real y) @trusted pure nothrow @nogc
}
}
// /
deprecated
@safe pure nothrow @nogc unittest
{
assert (expi(1.3e5L ) == cos(1.3e5L ) + sin(1.3e5L ) * 1i);
Expand Down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty ugly, but my attempt at working around https://issues.dlang.org/show_bug.cgi?id=18251