Skip to content

Commit efced87

Browse files
n8shdlang-bot
authored andcommitted
Again use core.math intrinsics instead of std.math wrappers
As in PR dlang#7821 & PR dlang#7825. Mostly changes imports from std.math being divided into submodules.
1 parent 974a88a commit efced87

File tree

7 files changed

+43
-42
lines changed

7 files changed

+43
-42
lines changed

std/complex.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,9 +1105,9 @@ Complex!T atan(T)(Complex!T z) @safe pure nothrow @nogc
11051105
*/
11061106
Complex!T sinh(T)(Complex!T z) @safe pure nothrow @nogc
11071107
{
1108-
static import std.math;
1109-
return Complex!T(std.math.sinh(z.re) * std.math.cos(z.im),
1110-
std.math.cosh(z.re) * std.math.sin(z.im));
1108+
static import core.math, std.math;
1109+
return Complex!T(std.math.sinh(z.re) * core.math.cos(z.im),
1110+
std.math.cosh(z.re) * core.math.sin(z.im));
11111111
}
11121112

11131113
///
@@ -1122,9 +1122,9 @@ Complex!T sinh(T)(Complex!T z) @safe pure nothrow @nogc
11221122
/// ditto
11231123
Complex!T cosh(T)(Complex!T z) @safe pure nothrow @nogc
11241124
{
1125-
static import std.math;
1126-
return Complex!T(std.math.cosh(z.re) * std.math.cos(z.im),
1127-
std.math.sinh(z.re) * std.math.sin(z.im));
1125+
static import core.math, std.math;
1126+
return Complex!T(std.math.cosh(z.re) * core.math.cos(z.im),
1127+
std.math.sinh(z.re) * core.math.sin(z.im));
11281128
}
11291129

11301130
///

std/internal/math/errorfunction.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
module std.internal.math.errorfunction;
2626
import std.math;
27-
import core.math : sqrt;
27+
import core.math : fabs, sqrt;
2828

2929
pure:
3030
nothrow:
@@ -836,7 +836,7 @@ real erf(real x)
836836
return -1.0;
837837
if (x == real.infinity)
838838
return 1.0;
839-
immutable ax = abs(x);
839+
immutable ax = fabs(x);
840840
if (ax > 1.0L)
841841
return 1.0L - erfc(x);
842842

@@ -932,7 +932,7 @@ real expx2(real x, int sign)
932932
const real M = 32_768.0;
933933
const real MINV = 3.0517578125e-5L;
934934

935-
x = abs(x);
935+
x = fabs(x);
936936
if (sign < 0)
937937
x = -x;
938938

@@ -985,7 +985,7 @@ Journal of Statistical Software <b>11</b>, (July 2004).
985985
real normalDistributionImpl(real a)
986986
{
987987
real x = a * SQRT1_2;
988-
real z = abs(x);
988+
real z = fabs(x);
989989

990990
if ( z < 1.0 )
991991
return 0.5L + 0.5L * erf(x);

std/math/algebraic.d

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ real hypot(real x, real y) @safe pure nothrow @nogc
302302
// If one is huge and the other tiny, return the larger.
303303
// If both are huge, avoid overflow by scaling by 1/sqrt(real.max/2).
304304
// If both are tiny, avoid underflow by scaling by sqrt(real.min_normal*real.epsilon).
305+
import core.math : fabs, sqrt;
305306

306307
enum real SQRTMIN = 0.5 * sqrt(real.min_normal); // This is a power of 2.
307308
enum real SQRTMAX = 1.0L / SQRTMIN; // 2^^((max_exp)/2) = nextUp(sqrt(real.max))
@@ -418,6 +419,7 @@ real hypot(real x, real y) @safe pure nothrow @nogc
418419
T hypot(T)(const T x, const T y, const T z) @safe pure nothrow @nogc
419420
if (isFloatingPoint!T)
420421
{
422+
import core.math : fabs, sqrt;
421423
import std.math.operations : fmax;
422424
const absx = fabs(x);
423425
const absy = fabs(y);
@@ -1010,7 +1012,7 @@ private T powIntegralImpl(PowType type, T)(T val)
10101012
private T powFloatingPointImpl(PowType type, T)(T x)
10111013
{
10121014
import std.math.traits : copysign, isFinite;
1013-
import std.math.exponential : frexp, ldexp;
1015+
import std.math.exponential : frexp;
10141016

10151017
if (!x.isFinite)
10161018
return x;
@@ -1022,9 +1024,9 @@ private T powFloatingPointImpl(PowType type, T)(T x)
10221024
auto y = frexp(x, exp);
10231025

10241026
static if (type == PowType.ceil)
1025-
y = ldexp(cast(T) 0.5, exp + 1);
1027+
y = core.math.ldexp(cast(T) 0.5, exp + 1);
10261028
else
1027-
y = ldexp(cast(T) 0.5, exp);
1029+
y = core.math.ldexp(cast(T) 0.5, exp);
10281030

10291031
if (!y.isFinite)
10301032
return cast(T) 0.0;

std/math/exponential.d

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ version (D_HardFloat)
6464
Unqual!F pow(F, G)(F x, G n) @nogc @trusted pure nothrow
6565
if (isFloatingPoint!(F) && isIntegral!(G))
6666
{
67-
import std.math.algebraic : abs;
67+
import core.math : fabs;
6868
import std.math.rounding : floor;
6969
import std.math.traits : isNaN;
7070
import std.traits : Unsigned;
@@ -100,13 +100,13 @@ if (isFloatingPoint!(F) && isIntegral!(G))
100100
//
101101
// We use the following two conclusions:
102102
//
103-
// m * floor(log2(abs(v))) >= F.max_exp
104-
// => abs(v) ^^ m > F.max == nextDown(F.infinity)
103+
// m * floor(log2(fabs(v))) >= F.max_exp
104+
// => fabs(v) ^^ m > F.max == nextDown(F.infinity)
105105
//
106106
// m * (bias - ex - 1) >= bias + F.mant_dig - 1
107-
// => abs(v) ^^ m < 2 ^^ (-bias - F.mant_dig + 2) == nextUp(0.0)
107+
// => fabs(v) ^^ m < 2 ^^ (-bias - F.mant_dig + 2) == nextUp(0.0)
108108
//
109-
// floor(log2(abs(v))) == ex - bias can be directly taken from the
109+
// floor(log2(fabs(v))) == ex - bias can be directly taken from the
110110
// exponent of the floating point represantation, to avoid long
111111
// calculations here.
112112

@@ -132,8 +132,8 @@ if (isFloatingPoint!(F) && isIntegral!(G))
132132
// in CTFE we cannot access the bit patterns and have therefore to
133133
// fall back to the (slower) general case
134134
// skipping subnormals by setting ex = bias
135-
ex = abs(v) == F.infinity ? 2 * bias + 1 :
136-
(abs(v) < F.min_normal ? bias : cast(ulong) (floor(log2(abs(v))) + bias));
135+
ex = fabs(v) == F.infinity ? 2 * bias + 1 :
136+
(fabs(v) < F.min_normal ? bias : cast(ulong) (floor(log2(fabs(v))) + bias));
137137
}
138138
else
139139
{
@@ -148,8 +148,8 @@ if (isFloatingPoint!(F) && isIntegral!(G))
148148
// In the general case we have to fall back to log2, which is slower, but still
149149
// a certain speed gain compared to not bailing out early.
150150
// skipping subnormals by setting ex = bias
151-
ulong ex = abs(v) == F.infinity ? 2 * bias + 1 :
152-
(abs(v) < F.min_normal ? bias : cast(ulong) (floor(log2(abs(v))) + bias));
151+
ulong ex = fabs(v) == F.infinity ? 2 * bias + 1 :
152+
(fabs(v) < F.min_normal ? bias : cast(ulong) (floor(log2(fabs(v))) + bias));
153153
}
154154

155155
// m * (...) can exceed ulong.max, we therefore first check m >= (...).
@@ -490,7 +490,7 @@ if (isIntegral!I && isFloatingPoint!F)
490490
Unqual!(Largest!(F, G)) pow(F, G)(F x, G y) @nogc @trusted pure nothrow
491491
if (isFloatingPoint!(F) && isFloatingPoint!(G))
492492
{
493-
import std.math.algebraic : fabs, sqrt;
493+
import core.math : fabs, sqrt;
494494
import std.math.traits : isInfinity, isNaN, signbit;
495495

496496
alias Float = typeof(return);
@@ -1203,7 +1203,7 @@ private T expImpl(T)(T x) @safe pure nothrow @nogc
12031203
}
12041204

12051205
// Scale by power of 2.
1206-
x = ldexp(x, n);
1206+
x = core.math.ldexp(x, n);
12071207

12081208
return x;
12091209
}
@@ -1697,7 +1697,7 @@ private T expm1Impl(T)(T x) @safe pure nothrow @nogc
16971697

16981698
// We have qx = exp(remainder LN2) - 1, so:
16991699
// exp(x) - 1 = 2^^n (qx + 1) - 1 = 2^^n qx + 2^^n - 1.
1700-
px = ldexp(cast(T) 1.0, n);
1700+
px = core.math.ldexp(cast(T) 1.0, n);
17011701
x = px * qx + (px - cast(T) 1.0);
17021702

17031703
return x;
@@ -2091,7 +2091,7 @@ private T exp2Impl(T)(T x) @nogc @safe pure nothrow
20912091
}
20922092

20932093
// Scale by power of 2.
2094-
x = ldexp(x, n);
2094+
x = core.math.ldexp(x, n);
20952095

20962096
return x;
20972097
}
@@ -3145,7 +3145,7 @@ real log(real x) @safe pure nothrow @nogc
31453145
real log10(real x) @safe pure nothrow @nogc
31463146
{
31473147
import std.math.constants : LOG2, LN2, SQRT1_2;
3148-
import std.math.algebraic : fabs, poly;
3148+
import std.math.algebraic : poly;
31493149
import std.math.traits : isNaN, isInfinity, signbit;
31503150

31513151
version (INLINE_YL2X)
@@ -3251,15 +3251,14 @@ real log10(real x) @safe pure nothrow @nogc
32513251
*/
32523252
real log1p(real x) @safe pure nothrow @nogc
32533253
{
3254-
import std.math.algebraic : fabs;
32553254
import std.math.traits : isNaN, isInfinity, signbit;
32563255
import std.math.constants : LN2;
32573256

32583257
version (INLINE_YL2X)
32593258
{
32603259
// On x87, yl2xp1 is valid if and only if -0.5 <= lg(x) <= 0.5,
32613260
// ie if -0.29 <= x <= 0.414
3262-
return (fabs(x) <= 0.25) ? core.math.yl2xp1(x, LN2) : core.math.yl2x(x+1, LN2);
3261+
return (core.math.fabs(x) <= 0.25) ? core.math.yl2xp1(x, LN2) : core.math.yl2x(x+1, LN2);
32633262
}
32643263
else
32653264
{

std/math/operations.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ int feqrel(X)(const X x, const X y) @trusted pure nothrow @nogc
866866
if (isFloatingPoint!(X))
867867
{
868868
import std.math : floatTraits, RealFormat;
869-
import std.math.algebraic : fabs;
869+
import core.math : fabs;
870870

871871
/* Public Domain. Author: Don Clugston, 18 Aug 2005.
872872
*/
@@ -1035,7 +1035,7 @@ if (isFloatingPoint!(X))
10351035
deprecated("approxEqual will be removed in 2.106.0. Please use isClose instead.")
10361036
bool approxEqual(T, U, V)(T value, U reference, V maxRelDiff = 1e-2, V maxAbsDiff = 1e-5)
10371037
{
1038-
import std.math.algebraic : fabs;
1038+
import core.math : fabs;
10391039
import std.range.primitives : empty, front, isInputRange, popFront;
10401040
static if (isInputRange!T)
10411041
{
@@ -1725,7 +1725,7 @@ if (isFloatingPoint!T)
17251725
{
17261726
if (__ctfe)
17271727
{
1728-
import std.math.algebraic : abs, fabs;
1728+
import core.math : fabs;
17291729
import std.math.rounding : floor;
17301730
import std.math.traits : isInfinity, isNaN;
17311731
import std.math.exponential : log2;
@@ -1737,7 +1737,7 @@ if (isFloatingPoint!T)
17371737
else if (fabs(val) >= nextUp(real.max / 2))
17381738
ret.exponent = 32766;
17391739
else
1740-
ret.exponent = cast(int) (val.abs.log2.floor() + 16383);
1740+
ret.exponent = cast(int) (val.fabs.log2.floor() + 16383);
17411741

17421742
if (ret.exponent == 32767)
17431743
{
@@ -1760,13 +1760,13 @@ if (isFloatingPoint!T)
17601760
val *= 2.0L ^^ delta;
17611761
}
17621762

1763-
ulong tmp = cast(ulong) abs(val);
1763+
ulong tmp = cast(ulong) fabs(val);
17641764
if (ret.exponent != 32767 && ret.exponent > 0 && tmp <= ulong.max / 2)
17651765
{
17661766
// correction, due to log2(val) being rounded up:
17671767
ret.exponent--;
17681768
val *= 2;
1769-
tmp = cast(ulong) abs(val);
1769+
tmp = cast(ulong) fabs(val);
17701770
}
17711771

17721772
ret.mantissa = tmp & ((1L << 63) - 1);

std/math/rounding.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ auto round(real x) @trusted nothrow @nogc
739739
FloatingPointControl.setControlState(
740740
(old & (-1 - FloatingPointControl.roundingMask)) | FloatingPointControl.roundToZero
741741
);
742-
x = rint((x >= 0) ? x + 0.5 : x - 0.5);
742+
x = core.math.rint((x >= 0) ? x + 0.5 : x - 0.5);
743743
FloatingPointControl.setControlState(old);
744744
return x;
745745
}

std/math/trigonometry.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ private T tanImpl(T)(T x) @safe pure nothrow @nogc
553553
*/
554554
real acos(real x) @safe pure nothrow @nogc
555555
{
556-
import std.math.algebraic : sqrt;
556+
import core.math : sqrt;
557557

558558
return atan2(sqrt(1-x*x), x);
559559
}
@@ -597,7 +597,7 @@ float acos(float x) @safe pure nothrow @nogc { return acos(cast(real) x); }
597597
*/
598598
real asin(real x) @safe pure nothrow @nogc
599599
{
600-
import std.math.algebraic : sqrt;
600+
import core.math : sqrt;
601601

602602
return atan2(x, sqrt(1-x*x));
603603
}
@@ -1181,7 +1181,7 @@ private F _sinh(F)(F x)
11811181
{
11821182
import std.math.traits : copysign;
11831183
import std.math.exponential : exp, expm1;
1184-
import std.math.algebraic : fabs;
1184+
import core.math : fabs;
11851185
import std.math.constants : LN2;
11861186

11871187
// sinh(x) = (exp(x)-exp(-x))/2;
@@ -1235,7 +1235,7 @@ private F _tanh(F)(F x)
12351235
{
12361236
import std.math.traits : copysign;
12371237
import std.math.exponential : expm1;
1238-
import std.math.algebraic : fabs;
1238+
import core.math : fabs;
12391239
import std.math.constants : LN2;
12401240

12411241
// tanh(x) = (exp(x) - exp(-x))/(exp(x)+exp(-x))
@@ -1297,7 +1297,7 @@ private F _acosh(F)(F x) @safe pure nothrow @nogc
12971297
{
12981298
import std.math.constants : LN2;
12991299
import std.math.exponential : log;
1300-
import std.math.algebraic : sqrt;
1300+
import core.math : sqrt;
13011301

13021302
if (x > 1/F.epsilon)
13031303
return F(LN2) + log(x);
@@ -1351,7 +1351,7 @@ float asinh(float x) @safe pure nothrow @nogc { return _asinh(x); }
13511351
private F _asinh(F)(F x)
13521352
{
13531353
import std.math.traits : copysign;
1354-
import std.math.algebraic : fabs, sqrt;
1354+
import core.math : fabs, sqrt;
13551355
import std.math.exponential : log, log1p;
13561356
import std.math.constants : LN2;
13571357

0 commit comments

Comments
 (0)