| 1 |
@safe pure nothrow @nogc unittest |
| 2 |
{ |
| 3 |
import std.math.algebraic; |
| 4 |
|
| 5 |
import std.math.traits : isIdentical, isNaN; |
| 6 |
|
| 7 |
assert(isIdentical(abs(-0.0L), 0.0L)); |
| 8 |
assert(isNaN(abs(real.nan))); |
| 9 |
assert(abs(-real.infinity) == real.infinity); |
| 10 |
assert(abs(-56) == 56); |
| 11 |
assert(abs(2321312L) == 2321312L); |
| 12 |
assert(abs(23u) == 23u); |
| 13 |
} |
| 14 |
|
| 15 |
@safe unittest |
| 16 |
{ |
| 17 |
import std.math.algebraic; |
| 18 |
|
| 19 |
import std.math.traits : isIdentical; |
| 20 |
|
| 21 |
assert(isIdentical(fabs(0.0f), 0.0f)); |
| 22 |
assert(isIdentical(fabs(-0.0f), 0.0f)); |
| 23 |
assert(fabs(-10.0f) == 10.0f); |
| 24 |
|
| 25 |
assert(isIdentical(fabs(0.0), 0.0)); |
| 26 |
assert(isIdentical(fabs(-0.0), 0.0)); |
| 27 |
assert(fabs(-10.0) == 10.0); |
| 28 |
|
| 29 |
assert(isIdentical(fabs(0.0L), 0.0L)); |
| 30 |
assert(isIdentical(fabs(-0.0L), 0.0L)); |
| 31 |
assert(fabs(-10.0L) == 10.0L); |
| 32 |
} |
| 33 |
|
| 34 |
@safe pure nothrow @nogc unittest |
| 35 |
{ |
| 36 |
import std.math.algebraic; |
| 37 |
|
| 38 |
import std.math.operations : feqrel; |
| 39 |
import std.math.traits : isNaN; |
| 40 |
|
| 41 |
assert(sqrt(2.0).feqrel(1.4142) > 16); |
| 42 |
assert(sqrt(9.0).feqrel(3.0) > 16); |
| 43 |
|
| 44 |
assert(isNaN(sqrt(-1.0f))); |
| 45 |
assert(isNaN(sqrt(-1.0))); |
| 46 |
assert(isNaN(sqrt(-1.0L))); |
| 47 |
} |
| 48 |
|
| 49 |
@safe unittest |
| 50 |
{ |
| 51 |
import std.math.algebraic; |
| 52 |
|
| 53 |
import std.math.operations : feqrel; |
| 54 |
|
| 55 |
assert(cbrt(1.0).feqrel(1.0) > 16); |
| 56 |
assert(cbrt(27.0).feqrel(3.0) > 16); |
| 57 |
assert(cbrt(15.625).feqrel(2.5) > 16); |
| 58 |
} |
| 59 |
|
| 60 |
@safe unittest |
| 61 |
{ |
| 62 |
import std.math.algebraic; |
| 63 |
|
| 64 |
import std.math.operations : feqrel; |
| 65 |
|
| 66 |
assert(hypot(1.0, 1.0).feqrel(1.4142) > 16); |
| 67 |
assert(hypot(3.0, 4.0).feqrel(5.0) > 16); |
| 68 |
assert(hypot(real.infinity, 1.0L) == real.infinity); |
| 69 |
assert(hypot(real.infinity, real.nan) == real.infinity); |
| 70 |
} |
| 71 |
|
| 72 |
@safe unittest |
| 73 |
{ |
| 74 |
import std.math.algebraic; |
| 75 |
|
| 76 |
import std.math.operations : isClose; |
| 77 |
|
| 78 |
assert(isClose(hypot(1.0, 2.0, 2.0), 3.0)); |
| 79 |
assert(isClose(hypot(2.0, 3.0, 6.0), 7.0)); |
| 80 |
assert(isClose(hypot(1.0, 4.0, 8.0), 9.0)); |
| 81 |
} |
| 82 |
|
| 83 |
@safe nothrow @nogc unittest |
| 84 |
{ |
| 85 |
import std.math.algebraic; |
| 86 |
|
| 87 |
real x = 3.1L; |
| 88 |
static real[] pp = [56.1L, 32.7L, 6]; |
| 89 |
|
| 90 |
assert(poly(x, pp) == (56.1L + (32.7L + 6.0L * x) * x)); |
| 91 |
} |
| 92 |
|
| 93 |
@safe @nogc pure nothrow unittest |
| 94 |
{ |
| 95 |
import std.math.algebraic; |
| 96 |
|
| 97 |
assert(nextPow2(2) == 4); |
| 98 |
assert(nextPow2(10) == 16); |
| 99 |
assert(nextPow2(4000) == 4096); |
| 100 |
|
| 101 |
assert(nextPow2(-2) == -4); |
| 102 |
assert(nextPow2(-10) == -16); |
| 103 |
|
| 104 |
assert(nextPow2(uint.max) == 0); |
| 105 |
assert(nextPow2(uint.min) == 0); |
| 106 |
assert(nextPow2(size_t.max) == 0); |
| 107 |
assert(nextPow2(size_t.min) == 0); |
| 108 |
|
| 109 |
assert(nextPow2(int.max) == 0); |
| 110 |
assert(nextPow2(int.min) == 0); |
| 111 |
assert(nextPow2(long.max) == 0); |
| 112 |
assert(nextPow2(long.min) == 0); |
| 113 |
} |
| 114 |
|
| 115 |
@safe @nogc pure nothrow unittest |
| 116 |
{ |
| 117 |
import std.math.algebraic; |
| 118 |
|
| 119 |
assert(nextPow2(2.1) == 4.0); |
| 120 |
assert(nextPow2(-2.0) == -4.0); |
| 121 |
assert(nextPow2(0.25) == 0.5); |
| 122 |
assert(nextPow2(-4.0) == -8.0); |
| 123 |
|
| 124 |
assert(nextPow2(double.max) == 0.0); |
| 125 |
assert(nextPow2(double.infinity) == double.infinity); |
| 126 |
} |
| 127 |
|
| 128 |
@safe @nogc pure nothrow unittest |
| 129 |
{ |
| 130 |
import std.math.algebraic; |
| 131 |
|
| 132 |
assert(truncPow2(3) == 2); |
| 133 |
assert(truncPow2(4) == 4); |
| 134 |
assert(truncPow2(10) == 8); |
| 135 |
assert(truncPow2(4000) == 2048); |
| 136 |
|
| 137 |
assert(truncPow2(-5) == -4); |
| 138 |
assert(truncPow2(-20) == -16); |
| 139 |
|
| 140 |
assert(truncPow2(uint.max) == int.max + 1); |
| 141 |
assert(truncPow2(uint.min) == 0); |
| 142 |
assert(truncPow2(ulong.max) == long.max + 1); |
| 143 |
assert(truncPow2(ulong.min) == 0); |
| 144 |
|
| 145 |
assert(truncPow2(int.max) == (int.max / 2) + 1); |
| 146 |
assert(truncPow2(int.min) == int.min); |
| 147 |
assert(truncPow2(long.max) == (long.max / 2) + 1); |
| 148 |
assert(truncPow2(long.min) == long.min); |
| 149 |
} |
| 150 |
|
| 151 |
@safe @nogc pure nothrow unittest |
| 152 |
{ |
| 153 |
import std.math.algebraic; |
| 154 |
|
| 155 |
assert(truncPow2(2.1) == 2.0); |
| 156 |
assert(truncPow2(7.0) == 4.0); |
| 157 |
assert(truncPow2(-1.9) == -1.0); |
| 158 |
assert(truncPow2(0.24) == 0.125); |
| 159 |
assert(truncPow2(-7.0) == -4.0); |
| 160 |
|
| 161 |
assert(truncPow2(double.infinity) == double.infinity); |
| 162 |
} |
| 163 |
|