mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
apply all-man braces in Phobos
// find common cases sed -E "s/^(\s*)((if|static if|for|foreach|foreach_reverse|while|unittest|switch|else|version).*)\s*\{$/\1\2\n\1{/" -i **/*.d // catch else-if sed -E "s/^(\s*)} (else static if| if|else if|else)(.*)\s*\{$/\1}\n\1\2\3\n\1{/" -i **/*.d // remove created trailing whitespace sed -i 's/[ \t]*$//' **/*.d
This commit is contained in:
parent
f276dbc06b
commit
1d34a121e9
47 changed files with 1180 additions and 537 deletions
|
@ -115,7 +115,8 @@ alias CURL = void;
|
|||
alias curl_socket_t = socket_t;
|
||||
|
||||
/// jdrewsen - Would like to get socket error constant from std.socket by it is private atm.
|
||||
version(Windows) {
|
||||
version(Windows)
|
||||
{
|
||||
private import core.sys.windows.windows, core.sys.windows.winsock2;
|
||||
enum CURL_SOCKET_BAD = SOCKET_ERROR;
|
||||
}
|
||||
|
|
|
@ -1284,7 +1284,8 @@ void gzclearerr (gzFile file);
|
|||
|
||||
uint adler = adler32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
while (read_buffer(buffer, length) != EOF)
|
||||
{
|
||||
adler = adler32(adler, buffer, length);
|
||||
}
|
||||
if (adler != original_adler) error();
|
||||
|
@ -1308,7 +1309,8 @@ uint crc32(uint crc, ubyte* buf, uint len);
|
|||
|
||||
uint crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
while (read_buffer(buffer, length) != EOF) {
|
||||
while (read_buffer(buffer, length) != EOF)
|
||||
{
|
||||
crc = crc32(crc, buffer, length);
|
||||
}
|
||||
if (crc != original_crc) error();
|
||||
|
|
|
@ -923,13 +923,15 @@ private struct Levenshtein(Range, alias equals, CostType = size_t)
|
|||
EditOp[] result;
|
||||
size_t i = rows - 1, j = cols - 1;
|
||||
// restore the path
|
||||
while (i || j) {
|
||||
while (i || j)
|
||||
{
|
||||
auto cIns = j == 0 ? CostType.max : matrix(i,j - 1);
|
||||
auto cDel = i == 0 ? CostType.max : matrix(i - 1,j);
|
||||
auto cSub = i == 0 || j == 0
|
||||
? CostType.max
|
||||
: matrix(i - 1,j - 1);
|
||||
switch (min_index(cSub, cIns, cDel)) {
|
||||
switch (min_index(cSub, cIns, cDel))
|
||||
{
|
||||
case 0:
|
||||
result ~= matrix(i - 1,j - 1) == matrix(i,j)
|
||||
? EditOp.none
|
||||
|
@ -968,7 +970,8 @@ private:
|
|||
void AllocMatrix(size_t r, size_t c) @trusted {
|
||||
rows = r;
|
||||
cols = c;
|
||||
if (_matrix.length < r * c) {
|
||||
if (_matrix.length < r * c)
|
||||
{
|
||||
import core.stdc.stdlib : realloc;
|
||||
import core.exception : onOutOfMemoryError;
|
||||
auto m = cast(CostType *)realloc(_matrix.ptr, r * c * _matrix[0].sizeof);
|
||||
|
|
|
@ -1154,12 +1154,14 @@ private struct FilterResult(alias pred, Range)
|
|||
static assert(isInfinite!(typeof(infinite)));
|
||||
static assert(isForwardRange!(typeof(infinite)));
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
DummyType d;
|
||||
auto f = filter!"a & 1"(d);
|
||||
assert(equal(f, [1,3,5,7,9]));
|
||||
|
||||
static if (isForwardRange!DummyType) {
|
||||
static if (isForwardRange!DummyType)
|
||||
{
|
||||
static assert(isForwardRange!(typeof(f)));
|
||||
}
|
||||
}
|
||||
|
@ -1416,7 +1418,8 @@ struct Group(alias pred, R) if (isInputRange!R)
|
|||
return _current;
|
||||
}
|
||||
|
||||
static if (isForwardRange!R) {
|
||||
static if (isForwardRange!R)
|
||||
{
|
||||
///
|
||||
@property typeof(this) save() {
|
||||
typeof(this) ret = this;
|
||||
|
@ -1451,7 +1454,8 @@ struct Group(alias pred, R) if (isInputRange!R)
|
|||
tuple(4, 3u), tuple(5, 1u) ][]));
|
||||
static assert(isForwardRange!(typeof(group(arr))));
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
DummyType d;
|
||||
auto g = group(d);
|
||||
|
||||
|
@ -2480,7 +2484,8 @@ unittest
|
|||
// Can't use array() or equal() directly because they fail with transient
|
||||
// .front.
|
||||
int[] result;
|
||||
foreach (c; rr.joiner()) {
|
||||
foreach (c; rr.joiner())
|
||||
{
|
||||
result ~= c;
|
||||
}
|
||||
|
||||
|
@ -2525,7 +2530,8 @@ unittest
|
|||
// Can't use array() or equal() directly because they fail with transient
|
||||
// .front.
|
||||
dchar[] result;
|
||||
foreach (c; rr.joiner()) {
|
||||
foreach (c; rr.joiner())
|
||||
{
|
||||
result ~= c;
|
||||
}
|
||||
|
||||
|
@ -3715,7 +3721,8 @@ if (is(typeof(binaryFun!pred(r.front, s)) : bool)
|
|||
assert(split.back == "r ");
|
||||
|
||||
foreach (DummyType; AllDummyRanges) { // Bug 4408
|
||||
static if (isRandomAccessRange!DummyType) {
|
||||
static if (isRandomAccessRange!DummyType)
|
||||
{
|
||||
static assert(isBidirectionalRange!DummyType);
|
||||
DummyType d;
|
||||
auto s = splitter(d, 5);
|
||||
|
@ -4369,8 +4376,10 @@ if (isSomeChar!C)
|
|||
lines[0] = "line one".dup;
|
||||
lines[1] = "line \ttwo".dup;
|
||||
lines[2] = "yah last line\ryah".dup;
|
||||
foreach (line; lines) {
|
||||
foreach (word; splitter(strip(line))) {
|
||||
foreach (line; lines)
|
||||
{
|
||||
foreach (word; splitter(strip(line)))
|
||||
{
|
||||
if (word in dictionary) continue; // Nothing to do
|
||||
auto newID = dictionary.length;
|
||||
dictionary[to!string(word)] = cast(uint)newID;
|
||||
|
@ -4843,7 +4852,8 @@ private struct UniqResult(alias pred, Range)
|
|||
@property bool empty() { return _input.empty; }
|
||||
}
|
||||
|
||||
static if (isForwardRange!Range) {
|
||||
static if (isForwardRange!Range)
|
||||
{
|
||||
@property typeof(this) save() {
|
||||
return typeof(this)(_input.save);
|
||||
}
|
||||
|
@ -4865,14 +4875,16 @@ private struct UniqResult(alias pred, Range)
|
|||
assert(equal(r, [ 1, 2, 3, 4, 5 ][]));
|
||||
assert(equal(retro(r), retro([ 1, 2, 3, 4, 5 ][])));
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
DummyType d;
|
||||
auto u = uniq(d);
|
||||
assert(equal(u, [1,2,3,4,5,6,7,8,9,10]));
|
||||
|
||||
static assert(d.rt == RangeType.Input || isForwardRange!(typeof(u)));
|
||||
|
||||
static if (d.rt >= RangeType.Bidirectional) {
|
||||
static if (d.rt >= RangeType.Bidirectional)
|
||||
{
|
||||
assert(equal(retro(u), [10,9,8,7,6,5,4,3,2,1]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2396,7 +2396,8 @@ Params:
|
|||
*/
|
||||
void swapAt(R)(auto ref R r, size_t i1, size_t i2)
|
||||
{
|
||||
static if (is(typeof(&r.swapAt))) {
|
||||
static if (is(typeof(&r.swapAt)))
|
||||
{
|
||||
r.swapAt(i1, i2);
|
||||
}
|
||||
else static if (is(typeof(&r[i1])))
|
||||
|
|
|
@ -305,7 +305,8 @@ is ignored.
|
|||
import std.algorithm.comparison : equal;
|
||||
ptrdiff_t virtual_begin = needle.length - offset - portion;
|
||||
ptrdiff_t ignore = 0;
|
||||
if (virtual_begin < 0) {
|
||||
if (virtual_begin < 0)
|
||||
{
|
||||
ignore = -virtual_begin;
|
||||
virtual_begin = 0;
|
||||
}
|
||||
|
@ -2173,7 +2174,8 @@ if (Ranges.length > 1 && is(typeof(startsWith!pred(haystack, needles))))
|
|||
assert(find(a, b) == [ 1, 2, 3, 4, 5 ]);
|
||||
assert(find(b, a).empty);
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
DummyType d;
|
||||
auto findRes = find(d, 5);
|
||||
assert(equal(findRes, [5,6,7,8,9,10]));
|
||||
|
@ -2206,7 +2208,8 @@ Range1 find(Range1, alias pred, Range2)(
|
|||
"(.gnu.linkonce.tmain+0x74): In function `main' undefined reference"~
|
||||
" to `_Dmain':";
|
||||
string[] ns = ["libphobos", "function", " undefined", "`", ":"];
|
||||
foreach (n ; ns) {
|
||||
foreach (n ; ns)
|
||||
{
|
||||
auto p = find(h, boyerMooreFinder(n));
|
||||
assert(!p.empty);
|
||||
}
|
||||
|
|
|
@ -998,7 +998,8 @@ private size_t getPivot(alias less, Range)(Range r)
|
|||
((cast(uint) (pred(r[0], r[len - 1]))) << 1) |
|
||||
(cast(uint) (pred(r[mid], r[len - 1])));
|
||||
|
||||
switch (result) {
|
||||
switch (result)
|
||||
{
|
||||
case 0b001:
|
||||
r.swapAt(0, len - 1);
|
||||
r.swapAt(0, mid);
|
||||
|
@ -1070,7 +1071,8 @@ private void optimisticInsertionSort(alias less, Range)(Range r)
|
|||
|
||||
auto rnd = Random(1);
|
||||
auto a = new int[uniform(100, 200, rnd)];
|
||||
foreach (ref e; a) {
|
||||
foreach (ref e; a)
|
||||
{
|
||||
e = uniform(-100, 100, rnd);
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1218,8 @@ unittest
|
|||
// sort using delegate
|
||||
auto a = new int[100];
|
||||
auto rnd = Random(unpredictableSeed);
|
||||
foreach (ref e; a) {
|
||||
foreach (ref e; a)
|
||||
{
|
||||
e = uniform(-100, 100, rnd);
|
||||
}
|
||||
|
||||
|
@ -1231,7 +1234,8 @@ unittest
|
|||
assert(isSorted!("a < b")(a));
|
||||
|
||||
// sort using function; all elements equal
|
||||
foreach (ref e; a) {
|
||||
foreach (ref e; a)
|
||||
{
|
||||
e = 5;
|
||||
}
|
||||
static bool less(int a, int b) { return a < b; }
|
||||
|
@ -2223,7 +2227,8 @@ unittest
|
|||
|
||||
static double entropy(double[] probs) {
|
||||
double result = 0;
|
||||
foreach (p; probs) {
|
||||
foreach (p; probs)
|
||||
{
|
||||
if (!p) continue;
|
||||
//enforce(p > 0 && p <= 1, "Wrong probability passed to entropy");
|
||||
result -= p * log2(p);
|
||||
|
@ -2256,7 +2261,8 @@ unittest
|
|||
|
||||
static double entropy(double[] probs) {
|
||||
double result = 0;
|
||||
foreach (p; probs) {
|
||||
foreach (p; probs)
|
||||
{
|
||||
if (!p) continue;
|
||||
//enforce(p > 0 && p <= 1, "Wrong probability passed to entropy");
|
||||
result -= p * log2(p);
|
||||
|
@ -2799,7 +2805,8 @@ bool nextPermutation(alias less="a < b", BidirectionalRange)
|
|||
break;
|
||||
}
|
||||
|
||||
if (i.empty) {
|
||||
if (i.empty)
|
||||
{
|
||||
// Entire range is decreasing: it's lexicographically the greatest. So
|
||||
// wrap it around.
|
||||
range.reverse();
|
||||
|
|
|
@ -2966,7 +2966,8 @@ if (isDynamicArray!A)
|
|||
}
|
||||
|
||||
///
|
||||
unittest{
|
||||
unittest
|
||||
{
|
||||
auto app = appender!string();
|
||||
string b = "abcdefg";
|
||||
foreach (char c; b)
|
||||
|
|
19
std/bigint.d
19
std/bigint.d
|
@ -223,10 +223,13 @@ public:
|
|||
}
|
||||
else static if (op=="*")
|
||||
{
|
||||
if (y == 0) {
|
||||
if (y == 0)
|
||||
{
|
||||
sign = false;
|
||||
data = 0UL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sign = ( sign != (y<0) );
|
||||
data = BigUint.mulInt(data, u);
|
||||
}
|
||||
|
@ -1095,7 +1098,8 @@ Unsigned!T absUnsign(T)(T x) if (isIntegral!T)
|
|||
}
|
||||
|
||||
nothrow pure
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
BigInt a, b;
|
||||
a = 1;
|
||||
b = 2;
|
||||
|
@ -1103,7 +1107,8 @@ unittest {
|
|||
}
|
||||
|
||||
nothrow pure
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
long a;
|
||||
BigInt b;
|
||||
auto c = a + b;
|
||||
|
@ -1111,7 +1116,8 @@ unittest {
|
|||
}
|
||||
|
||||
nothrow pure
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
BigInt x = 1, y = 2;
|
||||
assert(x < y);
|
||||
assert(x <= y);
|
||||
|
@ -1134,7 +1140,8 @@ unittest {
|
|||
assert(incr == BigInt(1));
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
// Radix conversion
|
||||
assert( toDecimalString(BigInt("-1_234_567_890_123_456_789"))
|
||||
== "-1234567890123456789");
|
||||
|
|
|
@ -807,7 +807,8 @@ Complex!T cos(T)(Complex!T z) @safe pure nothrow @nogc
|
|||
}
|
||||
|
||||
///
|
||||
unittest{
|
||||
unittest
|
||||
{
|
||||
import std.math;
|
||||
import std.complex;
|
||||
assert(cos(complex(0.0)) == 1.0);
|
||||
|
|
|
@ -1716,11 +1716,16 @@ void yield(T)(T value)
|
|||
}
|
||||
|
||||
|
||||
version (Win64) {
|
||||
version (Win64)
|
||||
{
|
||||
// fibers are broken on Win64
|
||||
} else version (Win32) {
|
||||
}
|
||||
else version (Win32)
|
||||
{
|
||||
// fibers are broken in Win32 under server 2012: bug 13821
|
||||
} else unittest {
|
||||
}
|
||||
else unittest
|
||||
{
|
||||
import core.exception;
|
||||
import std.exception;
|
||||
|
||||
|
|
|
@ -1291,7 +1291,8 @@ unittest
|
|||
}
|
||||
|
||||
// Test issue 11194
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
static struct S {
|
||||
int i = 1337;
|
||||
void* p;
|
||||
|
|
|
@ -1051,6 +1051,7 @@ Complexity: $(BIGOH n)
|
|||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
TotalContainer!int test;
|
||||
}
|
||||
|
|
|
@ -2001,7 +2001,8 @@ pure unittest
|
|||
assert(array(rt4[]) == ["hello"]);
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
import std.conv : to;
|
||||
|
||||
auto rt1 = redBlackTree!string();
|
||||
|
|
|
@ -148,7 +148,8 @@ class CFile : Stream {
|
|||
}
|
||||
|
||||
// run a few tests
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
import std.file : deleteme;
|
||||
import std.internal.cstring : tempCString;
|
||||
|
||||
|
@ -203,7 +204,8 @@ class CFile : Stream {
|
|||
file.writeLine("That was blank");
|
||||
file.position = 0;
|
||||
char[][] lines;
|
||||
foreach (char[] line; file) {
|
||||
foreach (char[] line; file)
|
||||
{
|
||||
lines ~= line.dup;
|
||||
}
|
||||
assert( lines.length == 5 );
|
||||
|
@ -213,7 +215,8 @@ class CFile : Stream {
|
|||
assert( lines[3] == "That was blank");
|
||||
file.position = 0;
|
||||
lines = new char[][5];
|
||||
foreach (ulong n, char[] line; file) {
|
||||
foreach (ulong n, char[] line; file)
|
||||
{
|
||||
lines[cast(size_t)(n-1)] = line.dup;
|
||||
}
|
||||
assert( lines[0] == "Testing stream.d:");
|
||||
|
|
16
std/csv.d
16
std/csv.d
|
@ -614,7 +614,8 @@ unittest
|
|||
(str, ["b","a"], ',', '"');
|
||||
|
||||
auto ans2 = [["Hello","65"],["World","123"]];
|
||||
foreach (record; records2) {
|
||||
foreach (record; records2)
|
||||
{
|
||||
assert(equal(record, ans2.front));
|
||||
ans2.popFront();
|
||||
}
|
||||
|
@ -624,7 +625,8 @@ unittest
|
|||
(str, ["a","b","c","d"], ',', '"');
|
||||
|
||||
ans2 = [["Joe","Carpenter"],["Fred","Fly"]];
|
||||
foreach (record; records2) {
|
||||
foreach (record; records2)
|
||||
{
|
||||
assert(equal(record, ans2.front));
|
||||
ans2.popFront();
|
||||
}
|
||||
|
@ -1161,7 +1163,8 @@ public:
|
|||
// to eliminate so many tokens. This calculates
|
||||
// how many will be skipped to get to the next header column
|
||||
size_t normalizer;
|
||||
foreach (ref c; _popCount) {
|
||||
foreach (ref c; _popCount)
|
||||
{
|
||||
static if (ErrorLevel == Malformed.ignore)
|
||||
{
|
||||
// If we are not throwing exceptions
|
||||
|
@ -1244,7 +1247,9 @@ public:
|
|||
"previous length of %s.", _input.row,
|
||||
_input.col, _input.rowLength));
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
static if (ErrorLevel == Malformed.throwException)
|
||||
if (_input.rowLength != 0)
|
||||
if (_input.col > _input.rowLength)
|
||||
|
@ -1314,7 +1319,8 @@ public:
|
|||
if (!_popCount.empty)
|
||||
_popCount.popFront();
|
||||
|
||||
if (skipNum == size_t.max) {
|
||||
if (skipNum == size_t.max)
|
||||
{
|
||||
while (!recordEnd())
|
||||
prime(1);
|
||||
_empty = true;
|
||||
|
|
|
@ -30314,7 +30314,8 @@ private:
|
|||
throw new DateTimeException(format("Both timezone files %s and %s do not exist.",
|
||||
combinedFile, indexFile));
|
||||
|
||||
foreach (Unused; 0 .. indexEntries) {
|
||||
foreach (Unused; 0 .. indexEntries)
|
||||
{
|
||||
string tzName = to!string(readVal!(char[])(tzFile, 40).ptr);
|
||||
uint tzOffset = readVal!uint(tzFile);
|
||||
readVal!(uint[])(tzFile, 2);
|
||||
|
|
|
@ -131,7 +131,8 @@ if (Targets.length >= 1 && !allSatisfy!(isMutable, Targets))
|
|||
alias implementsInterface = .implementsInterface!(Source, staticMap!(Unqual, Targets));
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
interface Foo {
|
||||
void foo();
|
||||
}
|
||||
|
|
|
@ -4884,7 +4884,8 @@ private TypeInfo primitiveTypeInfo(Mangle m)
|
|||
{
|
||||
// BUG: should fix this in static this() to avoid double checked locking bug
|
||||
__gshared TypeInfo[Mangle] dic;
|
||||
if (!dic.length) {
|
||||
if (!dic.length)
|
||||
{
|
||||
dic = [
|
||||
Mangle.Tvoid : typeid(void),
|
||||
Mangle.Tbool : typeid(bool),
|
||||
|
|
|
@ -373,7 +373,8 @@ private uint _ctfeMatchBinary(string fun, string name1, string name2)
|
|||
return fun.length == 0;
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
|
||||
static assert(!_ctfeMatchBinary("sqrt(ё)", "ё", "b"));
|
||||
static assert(!_ctfeMatchBinary("ё.sqrt", "ё", "b"));
|
||||
|
@ -1272,7 +1273,8 @@ auto toDelegate(F)(auto ref F fp) if (isCallable!(F))
|
|||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
static int inc(ref uint num) {
|
||||
num++;
|
||||
return 8675309;
|
||||
|
|
|
@ -1123,7 +1123,8 @@ T intpow(T)(T x, ulong n) pure nothrow @safe
|
|||
|
||||
default:
|
||||
p = 1;
|
||||
while (1){
|
||||
while (1)
|
||||
{
|
||||
if (n & 1)
|
||||
p *= x;
|
||||
n >>= 1;
|
||||
|
|
|
@ -262,7 +262,8 @@ unittest
|
|||
It is defined in this way to allow cache-efficient multiplication.
|
||||
This function is equivalent to:
|
||||
----
|
||||
for (size_t i = 0; i< right.length; ++i) {
|
||||
for (size_t i = 0; i< right.length; ++i)
|
||||
{
|
||||
dest[left.length + i] = multibyteMulAdd(dest[i..left.length+i],
|
||||
left, right[i], 0);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,8 @@ nothrow:
|
|||
(b) compiler bugs prevent the use of .ptr when a frame pointer is used.
|
||||
*/
|
||||
|
||||
version(D_InlineAsm_X86) {
|
||||
version(D_InlineAsm_X86)
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
|
@ -72,12 +73,15 @@ private:
|
|||
string indexedLoopUnroll(int n, string s) pure @safe
|
||||
{
|
||||
string u;
|
||||
for (int i = 0; i<n; ++i) {
|
||||
for (int i = 0; i<n; ++i)
|
||||
{
|
||||
string nstr= (i>9 ? ""~ cast(char)('0'+i/10) : "") ~ cast(char)('0' + i%10);
|
||||
|
||||
int last = 0;
|
||||
for (int j = 0; j<s.length; ++j) {
|
||||
if (s[j]=='@') {
|
||||
for (int j = 0; j<s.length; ++j)
|
||||
{
|
||||
if (s[j]=='@')
|
||||
{
|
||||
u ~= s[last..j] ~ nstr;
|
||||
last = j+1;
|
||||
}
|
||||
|
@ -203,7 +207,8 @@ unittest
|
|||
assert(a[11]==0);
|
||||
for (int i=0; i<10; ++i) if (i!=5) assert(a[i]==0);
|
||||
|
||||
for (int q=3; q<36;++q) {
|
||||
for (int q=3; q<36;++q)
|
||||
{
|
||||
for (int i=0; i<a.length; ++i)
|
||||
{
|
||||
a[i]=b[i]=c[i]=0;
|
||||
|
@ -741,9 +746,12 @@ uint multibyteMulAdd(char op)(uint [] dest, const uint [] src, uint
|
|||
// ESI = src
|
||||
|
||||
enum string OP = (op=='+')? "add" : "sub";
|
||||
version(D_PIC) {
|
||||
version(D_PIC)
|
||||
{
|
||||
enum { zero = 0 }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// use p2 (load unit) instead of the overworked p0 or p1 (ALU units)
|
||||
// when initializing registers to zero.
|
||||
__gshared int zero = 0;
|
||||
|
@ -804,7 +812,8 @@ unittest
|
|||
It is defined in this way to allow cache-efficient multiplication.
|
||||
This function is equivalent to:
|
||||
----
|
||||
for (int i = 0; i< right.length; ++i) {
|
||||
for (int i = 0; i< right.length; ++i)
|
||||
{
|
||||
dest[left.length + i] = multibyteMulAdd(dest[i..left.length+i],
|
||||
left, right[i], 0);
|
||||
}
|
||||
|
@ -821,9 +830,12 @@ void multibyteMultiplyAccumulate(uint [] dest, const uint[] left,
|
|||
// ESI = end of left. never changes
|
||||
// [ESP] = M = right[i] = multiplier for this pass through the loop.
|
||||
// right.length is changed into dest.ptr+dest.length
|
||||
version(D_PIC) {
|
||||
version(D_PIC)
|
||||
{
|
||||
enum { zero = 0 }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// use p2 (load unit) instead of the overworked p0 or p1 (ALU units)
|
||||
// when initializing registers to zero.
|
||||
__gshared int zero = 0;
|
||||
|
@ -1070,7 +1082,8 @@ unittest
|
|||
|
||||
void multibyteTriangleAccumulateD(uint[] dest, uint[] x) pure
|
||||
{
|
||||
for (int i = 0; i < x.length-3; ++i) {
|
||||
for (int i = 0; i < x.length-3; ++i)
|
||||
{
|
||||
dest[i+x.length] = multibyteMulAdd!('+')(
|
||||
dest[i+i+1 .. i+x.length], x[i+1..$], x[i], 0);
|
||||
}
|
||||
|
@ -1101,9 +1114,12 @@ void multibyteTriangleAccumulateAsm(uint[] dest, const uint[] src) pure
|
|||
// ESI = end of src. never changes
|
||||
// [ESP] = M = src[i] = multiplier for this pass through the loop.
|
||||
// dest.length is changed into dest.ptr+dest.length
|
||||
version(D_PIC) {
|
||||
version(D_PIC)
|
||||
{
|
||||
enum { zero = 0 }
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// use p2 (load unit) instead of the overworked p0 or p1 (ALU units)
|
||||
// when initializing registers to zero.
|
||||
__gshared int zero = 0;
|
||||
|
@ -1242,7 +1258,8 @@ unittest
|
|||
|
||||
void multibyteSquare(BigDigit[] result, const BigDigit [] x) pure
|
||||
{
|
||||
if (x.length < 4) {
|
||||
if (x.length < 4)
|
||||
{
|
||||
// Special cases, not worth doing triangular.
|
||||
result[x.length] = multibyteMul(result[0..x.length], x, x[0], 0);
|
||||
multibyteMultiplyAccumulate(result[1..$], x, x[1..$]);
|
||||
|
@ -1259,7 +1276,8 @@ void multibyteSquare(BigDigit[] result, const BigDigit [] x) pure
|
|||
multibyteAddDiagonalSquares(result, x);
|
||||
}
|
||||
|
||||
version(BignumPerformanceTest) {
|
||||
version(BignumPerformanceTest)
|
||||
{
|
||||
import core.stdc.stdio;
|
||||
int clock() { asm { push EBX; xor EAX, EAX; cpuid; pop EBX; rdtsc; } }
|
||||
|
||||
|
|
|
@ -124,7 +124,8 @@ real erfc(real a)
|
|||
|
||||
real z = -a * a;
|
||||
|
||||
if (z < -MAXLOG){
|
||||
if (z < -MAXLOG)
|
||||
{
|
||||
// mtherr( "erfcl", UNDERFLOW );
|
||||
if (a < 0) return 2.0;
|
||||
else return 0.0;
|
||||
|
@ -141,7 +142,8 @@ real erfc(real a)
|
|||
if (a < 0.0L)
|
||||
y = 2.0L - y;
|
||||
|
||||
if (y == 0.0) {
|
||||
if (y == 0.0)
|
||||
{
|
||||
// mtherr( "erfcl", UNDERFLOW );
|
||||
if (a < 0) return 2.0;
|
||||
else return 0.0;
|
||||
|
@ -161,9 +163,12 @@ real erfce(real x)
|
|||
{
|
||||
real y = 1.0/x;
|
||||
|
||||
if (x < 8.0) {
|
||||
if (x < 8.0)
|
||||
{
|
||||
return rationalPoly( y, P, Q);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return y * rationalPoly(y*y, R, S);
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +209,8 @@ real erf(real x)
|
|||
return x * rationalPoly(z, T, U);
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
// High resolution test points.
|
||||
enum real erfc0_250 = 0.723663330078125 + 1.0279753638067014931732235184287934646022E-5;
|
||||
enum real erfc0_375 = 0.5958709716796875 + 1.2118885490201676174914080878232469565953E-5;
|
||||
|
@ -283,7 +289,8 @@ real expx2(real x, int sign)
|
|||
real u = m * m;
|
||||
real u1 = 2 * m * f + f * f;
|
||||
|
||||
if (sign < 0) {
|
||||
if (sign < 0)
|
||||
{
|
||||
u = -u;
|
||||
u1 = -u1;
|
||||
}
|
||||
|
@ -325,7 +332,8 @@ real normalDistributionImpl(real a)
|
|||
|
||||
if ( z < 1.0 )
|
||||
return 0.5L + 0.5L * erf(x);
|
||||
else {
|
||||
else
|
||||
{
|
||||
real y = 0.5L * erfce(z);
|
||||
/* Multiply by exp(-x^2 / 2) */
|
||||
z = expx2(a, -1);
|
||||
|
@ -336,7 +344,8 @@ real normalDistributionImpl(real a)
|
|||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
assert(fabs(normalDistributionImpl(1L) - (0.841344746068543))< 0.0000000000000005);
|
||||
assert(isIdentical(normalDistributionImpl(NaN(0x325)), NaN(0x325)));
|
||||
}
|
||||
|
@ -420,14 +429,16 @@ static immutable real[8] Q3 =
|
|||
}
|
||||
int code = 1;
|
||||
real y = p;
|
||||
if ( y > (1.0L - EXP_2) ) {
|
||||
if ( y > (1.0L - EXP_2) )
|
||||
{
|
||||
y = 1.0L - y;
|
||||
code = 0;
|
||||
}
|
||||
|
||||
real x, z, y2, x0, x1;
|
||||
|
||||
if ( y > EXP_2 ) {
|
||||
if ( y > EXP_2 )
|
||||
{
|
||||
y = y - 0.5L;
|
||||
y2 = y * y;
|
||||
x = y + y * (y2 * rationalPoly( y2, P0, Q0));
|
||||
|
@ -437,22 +448,29 @@ static immutable real[8] Q3 =
|
|||
x = sqrt( -2.0L * log(y) );
|
||||
x0 = x - log(x)/x;
|
||||
z = 1.0L/x;
|
||||
if ( x < 8.0L ) {
|
||||
if ( x < 8.0L )
|
||||
{
|
||||
x1 = z * rationalPoly( z, P1, Q1);
|
||||
} else if ( x < 32.0L ) {
|
||||
}
|
||||
else if ( x < 32.0L )
|
||||
{
|
||||
x1 = z * rationalPoly( z, P2, Q2);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = z * rationalPoly( z, P3, Q3);
|
||||
}
|
||||
x = x0 - x1;
|
||||
if ( code != 0 ) {
|
||||
if ( code != 0 )
|
||||
{
|
||||
x = -x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
// TODO: Use verified test points.
|
||||
// The values below are from Excel 2003.
|
||||
assert(fabs(normalDistributionInvImpl(0.001) - (-3.09023230616779))< 0.00000000000005);
|
||||
|
|
|
@ -102,26 +102,32 @@ real gammaStirling(real x)
|
|||
|
||||
real w = 1.0L/x;
|
||||
real y = exp(x);
|
||||
if ( x > 1024.0L ) {
|
||||
if ( x > 1024.0L )
|
||||
{
|
||||
// For large x, use rational coefficients from the analytical expansion.
|
||||
w = poly(w, LargeStirlingCoeffs);
|
||||
// Avoid overflow in pow()
|
||||
real v = pow( x, 0.5L * x - 0.25L );
|
||||
y = v * (v / y);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
w = 1.0L + w * poly( w, SmallStirlingCoeffs);
|
||||
static if (floatTraits!(real).realFormat == RealFormat.ieeeDouble) {
|
||||
static if (floatTraits!(real).realFormat == RealFormat.ieeeDouble)
|
||||
{
|
||||
// Avoid overflow in pow() for 64-bit reals
|
||||
if (x > 143.0) {
|
||||
if (x > 143.0)
|
||||
{
|
||||
real v = pow( x, 0.5 * x - 0.25 );
|
||||
y = v * (v / y);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
y = pow( x, x - 0.5 ) / y;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
y = pow( x, x - 0.5L ) / y;
|
||||
}
|
||||
}
|
||||
|
@ -291,12 +297,14 @@ real gamma(real x)
|
|||
|
||||
q = fabs(x);
|
||||
|
||||
if ( q > 13.0L ) {
|
||||
if ( q > 13.0L )
|
||||
{
|
||||
// Large arguments are handled by Stirling's
|
||||
// formula. Large negative arguments are made positive using
|
||||
// the reflection formula.
|
||||
|
||||
if ( x < 0.0L ) {
|
||||
if ( x < 0.0L )
|
||||
{
|
||||
if (x < -1/real.epsilon)
|
||||
{
|
||||
// Large negatives lose all precision
|
||||
|
@ -310,7 +318,8 @@ real gamma(real x)
|
|||
if ( (intpart & 1) == 0 )
|
||||
sgngam = -1;
|
||||
z = q - p;
|
||||
if ( z > 0.5L ) {
|
||||
if ( z > 0.5L )
|
||||
{
|
||||
p += 1.0L;
|
||||
z = q - p;
|
||||
}
|
||||
|
@ -318,7 +327,9 @@ real gamma(real x)
|
|||
z = fabs(z) * gammaStirling(q);
|
||||
if ( z <= PI/real.max ) return sgngam * real.infinity;
|
||||
return sgngam * PI/z;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return gammaStirling(x);
|
||||
}
|
||||
}
|
||||
|
@ -328,30 +339,38 @@ real gamma(real x)
|
|||
// interval (2,3).
|
||||
|
||||
z = 1.0L;
|
||||
while ( x >= 3.0L ) {
|
||||
while ( x >= 3.0L )
|
||||
{
|
||||
x -= 1.0L;
|
||||
z *= x;
|
||||
}
|
||||
|
||||
while ( x < -0.03125L ) {
|
||||
while ( x < -0.03125L )
|
||||
{
|
||||
z /= x;
|
||||
x += 1.0L;
|
||||
}
|
||||
|
||||
if ( x <= 0.03125L ) {
|
||||
if ( x <= 0.03125L )
|
||||
{
|
||||
if ( x == 0.0L )
|
||||
return real.nan;
|
||||
else {
|
||||
if ( x < 0.0L ) {
|
||||
else
|
||||
{
|
||||
if ( x < 0.0L )
|
||||
{
|
||||
x = -x;
|
||||
return z / (x * poly( x, GammaSmallNegCoeffs ));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return z / (x * poly( x, GammaSmallCoeffs ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while ( x < 2.0L ) {
|
||||
while ( x < 2.0L )
|
||||
{
|
||||
z /= x;
|
||||
x += 1.0L;
|
||||
}
|
||||
|
@ -361,10 +380,12 @@ real gamma(real x)
|
|||
return z * poly( x, GammaNumeratorCoeffs ) / poly( x, GammaDenominatorCoeffs );
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
// gamma(n) = factorial(n-1) if n is an integer.
|
||||
real fact = 1.0L;
|
||||
for (int i=1; fact<real.max; ++i) {
|
||||
for (int i=1; fact<real.max; ++i)
|
||||
{
|
||||
// Require exact equality for small factorials
|
||||
if (i<14) assert(gamma(i*1.0L) == fact);
|
||||
assert(feqrel(gamma(i*1.0L), fact) >= real.mant_dig-15);
|
||||
|
@ -441,7 +462,8 @@ real logGamma(real x)
|
|||
if ( (intpart & 1) == 0 )
|
||||
sgngam = -1;
|
||||
z = q - p;
|
||||
if ( z > 0.5L ) {
|
||||
if ( z > 0.5L )
|
||||
{
|
||||
p += 1.0L;
|
||||
z = p - q;
|
||||
}
|
||||
|
@ -458,12 +480,14 @@ real logGamma(real x)
|
|||
z = 1.0L;
|
||||
nx = floor( x + 0.5L );
|
||||
f = x - nx;
|
||||
while ( x >= 3.0L ) {
|
||||
while ( x >= 3.0L )
|
||||
{
|
||||
nx -= 1.0L;
|
||||
x = nx + f;
|
||||
z *= x;
|
||||
}
|
||||
while ( x < 2.0L ) {
|
||||
while ( x < 2.0L )
|
||||
{
|
||||
if ( fabs(x) <= 0.03125 )
|
||||
{
|
||||
if ( x == 0.0L )
|
||||
|
@ -500,7 +524,8 @@ real logGamma(real x)
|
|||
return q ;
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
assert(isIdentical(logGamma(NaN(0xDEF)), NaN(0xDEF)));
|
||||
assert(logGamma(real.infinity) == real.infinity);
|
||||
assert(logGamma(-1.0) == real.infinity);
|
||||
|
@ -531,9 +556,11 @@ unittest {
|
|||
-3.5L, -1.30902099609375L + 1.43111007079536392848E-5L, 1.38887092635952890151E0L
|
||||
];
|
||||
// TODO: test derivatives as well.
|
||||
for (int i=0; i<testpoints.length; i+=3) {
|
||||
for (int i=0; i<testpoints.length; i+=3)
|
||||
{
|
||||
assert( feqrel(logGamma(testpoints[i]), testpoints[i+1]) > real.mant_dig-5);
|
||||
if (testpoints[i]<MAXGAMMA) {
|
||||
if (testpoints[i]<MAXGAMMA)
|
||||
{
|
||||
assert( feqrel(log(fabs(gamma(testpoints[i]))), testpoints[i+1]) > real.mant_dig-5);
|
||||
}
|
||||
}
|
||||
|
@ -548,11 +575,13 @@ unittest {
|
|||
|
||||
|
||||
private {
|
||||
static if (floatTraits!(real).realFormat == RealFormat.ieeeExtended) {
|
||||
static if (floatTraits!(real).realFormat == RealFormat.ieeeExtended)
|
||||
{
|
||||
enum real MAXLOG = 0x1.62e42fefa39ef358p+13L; // log(real.max)
|
||||
enum real MINLOG = -0x1.6436716d5406e6d8p+13L; // log(real.min_normal*real.epsilon) = log(smallest denormal)
|
||||
}
|
||||
else static if (floatTraits!(real).realFormat == RealFormat.ieeeDouble) {
|
||||
else static if (floatTraits!(real).realFormat == RealFormat.ieeeDouble)
|
||||
{
|
||||
enum real MAXLOG = 0x1.62e42fefa39efp+9L; // log(real.max)
|
||||
enum real MINLOG = -0x1.74385446d71c3p+9L; // log(real.min_normal*real.epsilon) = log(smallest denormal)
|
||||
}
|
||||
|
@ -591,13 +620,15 @@ real betaIncomplete(real aa, real bb, real xx )
|
|||
if ( isNaN(bb) ) return bb;
|
||||
return real.nan; // domain error
|
||||
}
|
||||
if (!(xx>0 && xx<1.0)) {
|
||||
if (!(xx>0 && xx<1.0))
|
||||
{
|
||||
if (isNaN(xx)) return xx;
|
||||
if ( xx == 0.0L ) return 0.0;
|
||||
if ( xx == 1.0L ) return 1.0;
|
||||
return real.nan; // domain error
|
||||
}
|
||||
if ( (bb * xx) <= 1.0L && xx <= 0.95L) {
|
||||
if ( (bb * xx) <= 1.0L && xx <= 0.95L)
|
||||
{
|
||||
return betaDistPowerSeries(aa, bb, xx);
|
||||
}
|
||||
real x;
|
||||
|
@ -607,21 +638,25 @@ real betaIncomplete(real aa, real bb, real xx )
|
|||
int flag = 0;
|
||||
|
||||
/* Reverse a and b if x is greater than the mean. */
|
||||
if ( xx > (aa/(aa+bb)) ) {
|
||||
if ( xx > (aa/(aa+bb)) )
|
||||
{
|
||||
// here x > aa/(aa+bb) and (bb*x>1 or x>0.95)
|
||||
flag = 1;
|
||||
a = bb;
|
||||
b = aa;
|
||||
xc = xx;
|
||||
x = 1.0L - xx;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
a = aa;
|
||||
b = bb;
|
||||
xc = 1.0L - xx;
|
||||
x = xx;
|
||||
}
|
||||
|
||||
if ( flag == 1 && (b * x) <= 1.0L && x <= 0.95L) {
|
||||
if ( flag == 1 && (b * x) <= 1.0L && x <= 0.95L)
|
||||
{
|
||||
// here xx > aa/(aa+bb) and ((bb*xx>1) or xx>0.95) and (aa*(1-xx)<=1) and xx > 0.05
|
||||
return 1.0 - betaDistPowerSeries(a, b, x); // note loss of precision
|
||||
}
|
||||
|
@ -631,9 +666,12 @@ real betaIncomplete(real aa, real bb, real xx )
|
|||
// One is for x * (a+b+2) < (a+1),
|
||||
// the other is for x * (a+b+2) > (a+1).
|
||||
real y = x * (a+b-2.0L) - (a-1.0L);
|
||||
if ( y < 0.0L ) {
|
||||
if ( y < 0.0L )
|
||||
{
|
||||
w = betaDistExpansion1( a, b, x );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
w = betaDistExpansion2( a, b, x ) / xc;
|
||||
}
|
||||
|
||||
|
@ -643,13 +681,16 @@ real betaIncomplete(real aa, real bb, real xx )
|
|||
|
||||
y = a * log(x);
|
||||
real t = b * log(xc);
|
||||
if ( (a+b) < MAXGAMMA && fabs(y) < MAXLOG && fabs(t) < MAXLOG ) {
|
||||
if ( (a+b) < MAXGAMMA && fabs(y) < MAXLOG && fabs(t) < MAXLOG )
|
||||
{
|
||||
t = pow(xc,b);
|
||||
t *= pow(x,a);
|
||||
t /= a;
|
||||
t *= w;
|
||||
t *= gamma(a+b) / (gamma(a) * gamma(b));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Resort to logarithms. */
|
||||
y += t + logGamma(a+b) - logGamma(a) - logGamma(b);
|
||||
y += log(w/a);
|
||||
|
@ -658,16 +699,21 @@ real betaIncomplete(real aa, real bb, real xx )
|
|||
/+
|
||||
// There seems to be a bug in Cephes at this point.
|
||||
// Problems occur for y > MAXLOG, not y < MINLOG.
|
||||
if ( y < MINLOG ) {
|
||||
if ( y < MINLOG )
|
||||
{
|
||||
t = 0.0L;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
t = exp(y);
|
||||
}
|
||||
+/
|
||||
}
|
||||
if ( flag == 1 ) {
|
||||
if ( flag == 1 )
|
||||
{
|
||||
/+ // CEPHES includes this code, but I think it is erroneous.
|
||||
if ( t <= real.epsilon ) {
|
||||
if ( t <= real.epsilon )
|
||||
{
|
||||
t = 1.0L - real.epsilon;
|
||||
} else
|
||||
+/
|
||||
|
@ -700,7 +746,8 @@ real betaIncompleteInv(real aa, real bb, real yy0 )
|
|||
yl = 0.0L;
|
||||
x1 = 1.0L;
|
||||
yh = 1.0L;
|
||||
if ( aa <= 1.0L || bb <= 1.0L ) {
|
||||
if ( aa <= 1.0L || bb <= 1.0L )
|
||||
{
|
||||
dithresh = 1.0e-7L;
|
||||
rflg = 0;
|
||||
a = aa;
|
||||
|
@ -710,7 +757,9 @@ real betaIncompleteInv(real aa, real bb, real yy0 )
|
|||
y = betaIncomplete( a, b, x );
|
||||
nflg = 0;
|
||||
goto ihalve;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
nflg = 0;
|
||||
dithresh = 1.0e-4L;
|
||||
}
|
||||
|
@ -719,13 +768,16 @@ real betaIncompleteInv(real aa, real bb, real yy0 )
|
|||
|
||||
yp = -normalDistributionInvImpl( yy0 );
|
||||
|
||||
if ( yy0 > 0.5L ) {
|
||||
if ( yy0 > 0.5L )
|
||||
{
|
||||
rflg = 1;
|
||||
a = bb;
|
||||
b = aa;
|
||||
y0 = 1.0L - yy0;
|
||||
yp = -yp;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rflg = 0;
|
||||
a = aa;
|
||||
b = bb;
|
||||
|
@ -738,7 +790,8 @@ real betaIncompleteInv(real aa, real bb, real yy0 )
|
|||
- ( 1.0L/(2.0L * b - 1.0L) - 1.0L/(2.0L * a - 1.0L) )
|
||||
* (lgm + (5.0L/6.0L) - 2.0L/(3.0L * x));
|
||||
d = 2.0L * d;
|
||||
if ( d < MINLOG ) {
|
||||
if ( d < MINLOG )
|
||||
{
|
||||
x = 1.0L;
|
||||
goto under;
|
||||
}
|
||||
|
@ -753,13 +806,17 @@ ihalve:
|
|||
|
||||
dir = 0;
|
||||
di = 0.5L;
|
||||
for ( i=0; i<400; i++ ) {
|
||||
if ( i != 0 ) {
|
||||
for ( i=0; i<400; i++ )
|
||||
{
|
||||
if ( i != 0 )
|
||||
{
|
||||
x = x0 + di * (x1 - x0);
|
||||
if ( x == 1.0L ) {
|
||||
if ( x == 1.0L )
|
||||
{
|
||||
x = 1.0L - real.epsilon;
|
||||
}
|
||||
if ( x == 0.0L ) {
|
||||
if ( x == 0.0L )
|
||||
{
|
||||
di = 0.5;
|
||||
x = x0 + di * (x1 - x0);
|
||||
if ( x == 0.0 )
|
||||
|
@ -773,10 +830,12 @@ ihalve:
|
|||
if ( fabs(yp) < dithresh )
|
||||
goto newt;
|
||||
}
|
||||
if ( y < y0 ) {
|
||||
if ( y < y0 )
|
||||
{
|
||||
x0 = x;
|
||||
yl = y;
|
||||
if ( dir < 0 ) {
|
||||
if ( dir < 0 )
|
||||
{
|
||||
dir = 0;
|
||||
di = 0.5L;
|
||||
} else if ( dir > 3 )
|
||||
|
@ -786,13 +845,17 @@ ihalve:
|
|||
else
|
||||
di = (y0 - y)/(yh - yl);
|
||||
dir += 1;
|
||||
if ( x0 > 0.95L ) {
|
||||
if ( rflg == 1 ) {
|
||||
if ( x0 > 0.95L )
|
||||
{
|
||||
if ( rflg == 1 )
|
||||
{
|
||||
rflg = 0;
|
||||
a = aa;
|
||||
b = bb;
|
||||
y0 = yy0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rflg = 1;
|
||||
a = bb;
|
||||
b = aa;
|
||||
|
@ -806,14 +869,18 @@ ihalve:
|
|||
yh = 1.0;
|
||||
goto ihalve;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = x;
|
||||
if ( rflg == 1 && x1 < real.epsilon ) {
|
||||
if ( rflg == 1 && x1 < real.epsilon )
|
||||
{
|
||||
x = 0.0L;
|
||||
goto done;
|
||||
}
|
||||
yh = y;
|
||||
if ( dir > 0 ) {
|
||||
if ( dir > 0 )
|
||||
{
|
||||
dir = 0;
|
||||
di = 0.5L;
|
||||
}
|
||||
|
@ -826,12 +893,14 @@ ihalve:
|
|||
dir -= 1;
|
||||
}
|
||||
}
|
||||
if ( x0 >= 1.0L ) {
|
||||
if ( x0 >= 1.0L )
|
||||
{
|
||||
// partial loss of precision
|
||||
x = 1.0L - real.epsilon;
|
||||
goto done;
|
||||
}
|
||||
if ( x <= 0.0L ) {
|
||||
if ( x <= 0.0L )
|
||||
{
|
||||
under:
|
||||
// underflow has occurred
|
||||
x = real.min_normal * real.min_normal;
|
||||
|
@ -840,26 +909,35 @@ under:
|
|||
|
||||
newt:
|
||||
|
||||
if ( nflg ) {
|
||||
if ( nflg )
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
nflg = 1;
|
||||
lgm = logGamma(a+b) - logGamma(a) - logGamma(b);
|
||||
|
||||
for ( i=0; i<15; i++ ) {
|
||||
for ( i=0; i<15; i++ )
|
||||
{
|
||||
/* Compute the function at this point. */
|
||||
if ( i != 0 )
|
||||
y = betaIncomplete(a,b,x);
|
||||
if ( y < yl ) {
|
||||
if ( y < yl )
|
||||
{
|
||||
x = x0;
|
||||
y = yl;
|
||||
} else if ( y > yh ) {
|
||||
}
|
||||
else if ( y > yh )
|
||||
{
|
||||
x = x1;
|
||||
y = yh;
|
||||
} else if ( y < y0 ) {
|
||||
}
|
||||
else if ( y < y0 )
|
||||
{
|
||||
x0 = x;
|
||||
yl = y;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = x;
|
||||
yh = y;
|
||||
}
|
||||
|
@ -867,23 +945,27 @@ newt:
|
|||
break;
|
||||
/* Compute the derivative of the function at this point. */
|
||||
d = (a - 1.0L) * log(x) + (b - 1.0L) * log(1.0L - x) + lgm;
|
||||
if ( d < MINLOG ) {
|
||||
if ( d < MINLOG )
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
if ( d > MAXLOG ) {
|
||||
if ( d > MAXLOG )
|
||||
{
|
||||
break;
|
||||
}
|
||||
d = exp(d);
|
||||
/* Compute the step to the next approximation of x. */
|
||||
d = (y - y0)/d;
|
||||
xt = x - d;
|
||||
if ( xt <= x0 ) {
|
||||
if ( xt <= x0 )
|
||||
{
|
||||
y = (x - x0) / (x1 - x0);
|
||||
xt = x0 + 0.5L * y * (x - x0);
|
||||
if ( xt <= 0.0L )
|
||||
break;
|
||||
}
|
||||
if ( xt >= x1 ) {
|
||||
if ( xt >= x1 )
|
||||
{
|
||||
y = (x1 - x) / (x1 - x0);
|
||||
xt = x1 - 0.5L * y * (x1 - x);
|
||||
if ( xt >= 1.0L )
|
||||
|
@ -898,7 +980,8 @@ newt:
|
|||
goto ihalve;
|
||||
|
||||
done:
|
||||
if ( rflg ) {
|
||||
if ( rflg )
|
||||
{
|
||||
if ( x <= real.epsilon )
|
||||
x = 1.0L - real.epsilon;
|
||||
else
|
||||
|
@ -1025,10 +1108,13 @@ real betaDistExpansion1(real a, real b, real x )
|
|||
|
||||
if ( qk != 0.0L )
|
||||
r = pk/qk;
|
||||
if ( r != 0.0L ) {
|
||||
if ( r != 0.0L )
|
||||
{
|
||||
t = fabs( (ans - r)/r );
|
||||
ans = r;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
t = 1.0L;
|
||||
}
|
||||
|
||||
|
@ -1044,13 +1130,15 @@ real betaDistExpansion1(real a, real b, real x )
|
|||
k7 += 2.0L;
|
||||
k8 += 2.0L;
|
||||
|
||||
if ( (fabs(qk) + fabs(pk)) > BETA_BIG ) {
|
||||
if ( (fabs(qk) + fabs(pk)) > BETA_BIG )
|
||||
{
|
||||
pkm2 *= BETA_BIGINV;
|
||||
pkm1 *= BETA_BIGINV;
|
||||
qkm2 *= BETA_BIGINV;
|
||||
qkm1 *= BETA_BIGINV;
|
||||
}
|
||||
if ( (fabs(qk) < BETA_BIGINV) || (fabs(pk) < BETA_BIGINV) ) {
|
||||
if ( (fabs(qk) < BETA_BIGINV) || (fabs(pk) < BETA_BIGINV) )
|
||||
{
|
||||
pkm2 *= BETA_BIG;
|
||||
pkm1 *= BETA_BIG;
|
||||
qkm2 *= BETA_BIG;
|
||||
|
@ -1109,7 +1197,8 @@ real betaDistExpansion2(real a, real b, real x )
|
|||
|
||||
if ( qk != 0.0L )
|
||||
r = pk/qk;
|
||||
if ( r != 0.0L ) {
|
||||
if ( r != 0.0L )
|
||||
{
|
||||
t = fabs( (ans - r)/r );
|
||||
ans = r;
|
||||
} else
|
||||
|
@ -1126,13 +1215,15 @@ real betaDistExpansion2(real a, real b, real x )
|
|||
k7 += 2.0L;
|
||||
k8 += 2.0L;
|
||||
|
||||
if ( (fabs(qk) + fabs(pk)) > BETA_BIG ) {
|
||||
if ( (fabs(qk) + fabs(pk)) > BETA_BIG )
|
||||
{
|
||||
pkm2 *= BETA_BIGINV;
|
||||
pkm1 *= BETA_BIGINV;
|
||||
qkm2 *= BETA_BIGINV;
|
||||
qkm1 *= BETA_BIGINV;
|
||||
}
|
||||
if ( (fabs(qk) < BETA_BIGINV) || (fabs(pk) < BETA_BIGINV) ) {
|
||||
if ( (fabs(qk) < BETA_BIGINV) || (fabs(pk) < BETA_BIGINV) )
|
||||
{
|
||||
pkm2 *= BETA_BIG;
|
||||
pkm1 *= BETA_BIG;
|
||||
qkm2 *= BETA_BIG;
|
||||
|
@ -1156,7 +1247,8 @@ real betaDistPowerSeries(real a, real b, real x )
|
|||
real n = 2.0L;
|
||||
real s = 0.0L;
|
||||
real z = real.epsilon * ai;
|
||||
while ( fabs(v) > z ) {
|
||||
while ( fabs(v) > z )
|
||||
{
|
||||
u = (n - b) * x / n;
|
||||
t *= u;
|
||||
v = t / (a + n);
|
||||
|
@ -1167,13 +1259,17 @@ real betaDistPowerSeries(real a, real b, real x )
|
|||
s += ai;
|
||||
|
||||
u = a * log(x);
|
||||
if ( (a+b) < MAXGAMMA && fabs(u) < MAXLOG ) {
|
||||
if ( (a+b) < MAXGAMMA && fabs(u) < MAXLOG )
|
||||
{
|
||||
t = gamma(a+b)/(gamma(a)*gamma(b));
|
||||
s = s * t * pow(x,a);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
t = logGamma(a+b) - logGamma(a) - logGamma(b) + u + log(s);
|
||||
|
||||
if ( t < MINLOG ) {
|
||||
if ( t < MINLOG )
|
||||
{
|
||||
s = 0.0L;
|
||||
} else
|
||||
s = exp(t);
|
||||
|
@ -1285,11 +1381,14 @@ body {
|
|||
real yc = y * c;
|
||||
pk = pkm1 * z - pkm2 * yc;
|
||||
qk = qkm1 * z - qkm2 * yc;
|
||||
if ( qk != 0.0L ) {
|
||||
if ( qk != 0.0L )
|
||||
{
|
||||
real r = pk/qk;
|
||||
t = fabs( (ans - r)/r );
|
||||
ans = r;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
t = 1.0L;
|
||||
}
|
||||
pkm2 = pkm1;
|
||||
|
@ -1299,7 +1398,8 @@ body {
|
|||
|
||||
const real BIG = 9.223372036854775808e18L;
|
||||
|
||||
if ( fabs(pk) > BIG ) {
|
||||
if ( fabs(pk) > BIG )
|
||||
{
|
||||
pkm2 /= BIG;
|
||||
pkm1 /= BIG;
|
||||
qkm2 /= BIG;
|
||||
|
@ -1349,16 +1449,20 @@ body {
|
|||
|
||||
lgm = logGamma(a);
|
||||
|
||||
for ( i=0; i<10; i++ ) {
|
||||
for ( i=0; i<10; i++ )
|
||||
{
|
||||
if ( x > x0 || x < x1 )
|
||||
goto ihalve;
|
||||
y = gammaIncompleteCompl(a,x);
|
||||
if ( y < yl || y > yh )
|
||||
goto ihalve;
|
||||
if ( y < y0 ) {
|
||||
if ( y < y0 )
|
||||
{
|
||||
x0 = x;
|
||||
yl = y;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = x;
|
||||
yh = y;
|
||||
}
|
||||
|
@ -1377,13 +1481,16 @@ body {
|
|||
/* Resort to interval halving if Newton iteration did not converge. */
|
||||
ihalve:
|
||||
d = 0.0625L;
|
||||
if ( x0 == real.max ) {
|
||||
if ( x0 == real.max )
|
||||
{
|
||||
if ( x <= 0.0L )
|
||||
x = 1.0L;
|
||||
while ( x0 == real.max ) {
|
||||
while ( x0 == real.max )
|
||||
{
|
||||
x = (1.0L + d) * x;
|
||||
y = gammaIncompleteCompl( a, x );
|
||||
if ( y < y0 ) {
|
||||
if ( y < y0 )
|
||||
{
|
||||
x0 = x;
|
||||
yl = y;
|
||||
break;
|
||||
|
@ -1394,7 +1501,8 @@ ihalve:
|
|||
d = 0.5L;
|
||||
dir = 0;
|
||||
|
||||
for ( i=0; i<400; i++ ) {
|
||||
for ( i=0; i<400; i++ )
|
||||
{
|
||||
x = x1 + d * (x0 - x1);
|
||||
y = gammaIncompleteCompl( a, x );
|
||||
lgm = (x0 - x1)/(x1 + x0);
|
||||
|
@ -1405,10 +1513,12 @@ ihalve:
|
|||
break;
|
||||
if ( x <= 0.0L )
|
||||
break;
|
||||
if ( y > y0 ) {
|
||||
if ( y > y0 )
|
||||
{
|
||||
x1 = x;
|
||||
yh = y;
|
||||
if ( dir < 0 ) {
|
||||
if ( dir < 0 )
|
||||
{
|
||||
dir = 0;
|
||||
d = 0.5L;
|
||||
} else if ( dir > 1 )
|
||||
|
@ -1416,10 +1526,13 @@ ihalve:
|
|||
else
|
||||
d = (y0 - yl)/(yh - yl);
|
||||
dir += 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
x0 = x;
|
||||
yl = y;
|
||||
if ( dir > 0 ) {
|
||||
if ( dir > 0 )
|
||||
{
|
||||
dir = 0;
|
||||
d = 0.5L;
|
||||
} else if ( dir < -1 )
|
||||
|
@ -1436,7 +1549,8 @@ ihalve:
|
|||
return x;
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
//Values from Excel's GammaInv(1-p, x, 1)
|
||||
assert(fabs(gammaIncompleteComplInv(1, 0.5) - 0.693147188044814) < 0.00000005);
|
||||
assert(fabs(gammaIncompleteComplInv(12, 0.99) - 5.42818075054289) < 0.00000005);
|
||||
|
@ -1489,36 +1603,44 @@ real digamma(real x)
|
|||
negative = 0;
|
||||
nz = 0.0;
|
||||
|
||||
if ( x <= 0.0 ) {
|
||||
if ( x <= 0.0 )
|
||||
{
|
||||
negative = 1;
|
||||
q = x;
|
||||
p = floor(q);
|
||||
if ( p == q ) {
|
||||
if ( p == q )
|
||||
{
|
||||
return real.nan; // singularity.
|
||||
}
|
||||
/* Remove the zeros of tan(PI x)
|
||||
* by subtracting the nearest integer from x
|
||||
*/
|
||||
nz = q - p;
|
||||
if ( nz != 0.5 ) {
|
||||
if ( nz > 0.5 ) {
|
||||
if ( nz != 0.5 )
|
||||
{
|
||||
if ( nz > 0.5 )
|
||||
{
|
||||
p += 1.0;
|
||||
nz = q - p;
|
||||
}
|
||||
nz = PI/tan(PI*nz);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
nz = 0.0;
|
||||
}
|
||||
x = 1.0 - x;
|
||||
}
|
||||
|
||||
// check for small positive integer
|
||||
if ((x <= 13.0) && (x == floor(x)) ) {
|
||||
if ((x <= 13.0) && (x == floor(x)) )
|
||||
{
|
||||
y = 0.0;
|
||||
n = lrint(x);
|
||||
// DAC: CEPHES bugfix. Cephes did this in reverse order, which
|
||||
// created a larger roundoff error.
|
||||
for (i=n-1; i>0; --i) {
|
||||
for (i=n-1; i>0; --i)
|
||||
{
|
||||
y+=1.0L/i;
|
||||
}
|
||||
y -= EULERGAMMA;
|
||||
|
@ -1527,12 +1649,14 @@ real digamma(real x)
|
|||
|
||||
s = x;
|
||||
w = 0.0;
|
||||
while ( s < 10.0 ) {
|
||||
while ( s < 10.0 )
|
||||
{
|
||||
w += 1.0/s;
|
||||
s += 1.0;
|
||||
}
|
||||
|
||||
if ( s < 1.0e17 ) {
|
||||
if ( s < 1.0e17 )
|
||||
{
|
||||
z = 1.0/(s * s);
|
||||
y = z * poly(z, Bn_n);
|
||||
} else
|
||||
|
@ -1541,13 +1665,15 @@ real digamma(real x)
|
|||
y = log(s) - 0.5L/s - y - w;
|
||||
|
||||
done:
|
||||
if ( negative ) {
|
||||
if ( negative )
|
||||
{
|
||||
y -= nz;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
// Exact values
|
||||
assert(digamma(1.0)== -EULERGAMMA);
|
||||
assert(feqrel(digamma(0.25), -PI/2 - 3* LN2 - EULERGAMMA) >= real.mant_dig-7);
|
||||
|
@ -1556,9 +1682,11 @@ unittest {
|
|||
assert(feqrel(digamma(2.5), -EULERGAMMA - 2*LN2 + 2.0 + 2.0L/3) >= real.mant_dig-9);
|
||||
assert(isIdentical(digamma(NaN(0xABC)), NaN(0xABC)));
|
||||
|
||||
for (int k=1; k<40; ++k) {
|
||||
for (int k=1; k<40; ++k)
|
||||
{
|
||||
real y=0;
|
||||
for (int u=k; u>=1; --u) {
|
||||
for (int u=k; u>=1; --u)
|
||||
{
|
||||
y += 1.0L/u;
|
||||
}
|
||||
assert(feqrel(digamma(k+1.0), -EULERGAMMA + y) >= real.mant_dig-2);
|
||||
|
@ -1587,13 +1715,15 @@ real logmdigamma(real x)
|
|||
|
||||
real s = x;
|
||||
real w = 0.0;
|
||||
while ( s < 10.0 ) {
|
||||
while ( s < 10.0 )
|
||||
{
|
||||
w += 1.0/s;
|
||||
s += 1.0;
|
||||
}
|
||||
|
||||
real y;
|
||||
if ( s < 1.0e17 ) {
|
||||
if ( s < 1.0e17 )
|
||||
{
|
||||
immutable real z = 1.0/(s * s);
|
||||
y = z * poly(z, Bn_n);
|
||||
} else
|
||||
|
@ -1602,7 +1732,8 @@ real logmdigamma(real x)
|
|||
return x == s ? y + 0.5L/s : (log(x/s) + 0.5L/s + y + w);
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
assert(logmdigamma(-5.0).isNaN());
|
||||
assert(isIdentical(logmdigamma(NaN(0xABC)), NaN(0xABC)));
|
||||
assert(logmdigamma(0.0) == real.infinity);
|
||||
|
@ -1654,7 +1785,8 @@ real logmdigammaInverse(real y)
|
|||
return y; //NaN
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
import std.typecons;
|
||||
//WolframAlpha, 22.02.2015
|
||||
immutable Tuple!(real, real)[5] testData = [
|
||||
|
|
|
@ -3958,7 +3958,8 @@ bool isHangT(dchar ch) @safe pure nothrow
|
|||
return false;
|
||||
}
|
||||
|
||||
static if (size_t.sizeof == 8) {
|
||||
static if (size_t.sizeof == 8)
|
||||
{
|
||||
//1536 bytes
|
||||
enum lowerCaseTrieEntries = TrieEntry!(bool, 8, 4, 9)([0x0, 0x20, 0x40],
|
||||
[0x100, 0x80, 0x2000], [0x402030202020100, 0x206020202020205,
|
||||
|
@ -7430,7 +7431,8 @@ enum toTitleSimpleIndexTrieEntries = TrieEntry!(ushort, 8, 7, 6)([0x0, 0x20,
|
|||
|
||||
}
|
||||
|
||||
static if (size_t.sizeof == 4) {
|
||||
static if (size_t.sizeof == 4)
|
||||
{
|
||||
//1536 bytes
|
||||
enum lowerCaseTrieEntries = TrieEntry!(bool, 8, 4, 9)([0x0, 0x40, 0x80],
|
||||
[0x100, 0x80, 0x2000], [0x2020100, 0x4020302, 0x2020205, 0x2060202,
|
||||
|
|
30
std/json.d
30
std/json.d
|
@ -378,7 +378,8 @@ struct JSONValue
|
|||
{
|
||||
static assert(is(Key : string), "AA key must be string");
|
||||
type_tag = JSON_TYPE.OBJECT;
|
||||
static if (is(Value : JSONValue)) {
|
||||
static if (is(Value : JSONValue))
|
||||
{
|
||||
store.object = arg;
|
||||
}
|
||||
else
|
||||
|
@ -848,7 +849,8 @@ if (isInputRange!T)
|
|||
}
|
||||
|
||||
bool tryGetSpecialFloat(string str, out double val) {
|
||||
switch (str) {
|
||||
switch (str)
|
||||
{
|
||||
case JSONFloatLiteral.nan:
|
||||
val = double.nan;
|
||||
return true;
|
||||
|
@ -1233,25 +1235,32 @@ string toJSON(const ref JSONValue root, in bool pretty = false, in JSONOptions o
|
|||
|
||||
auto val = value.store.floating;
|
||||
|
||||
if (val.isNaN) {
|
||||
if (options & JSONOptions.specialFloatLiterals) {
|
||||
if (val.isNaN)
|
||||
{
|
||||
if (options & JSONOptions.specialFloatLiterals)
|
||||
{
|
||||
toString(JSONFloatLiteral.nan);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
throw new JSONException(
|
||||
"Cannot encode NaN. Consider passing the specialFloatLiterals flag.");
|
||||
}
|
||||
}
|
||||
else if (val.isInfinity) {
|
||||
if (options & JSONOptions.specialFloatLiterals) {
|
||||
else if (val.isInfinity)
|
||||
{
|
||||
if (options & JSONOptions.specialFloatLiterals)
|
||||
{
|
||||
toString((val > 0) ? JSONFloatLiteral.inf : JSONFloatLiteral.negativeInf);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
throw new JSONException(
|
||||
"Cannot encode Infinity. Consider passing the specialFloatLiterals flag.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
json.put(to!string(val));
|
||||
}
|
||||
break;
|
||||
|
@ -1570,7 +1579,8 @@ unittest
|
|||
}`);
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
auto json = `"hello\nworld"`;
|
||||
const jv = parseJSON(json);
|
||||
assert(jv.toString == json);
|
||||
|
|
12
std/math.d
12
std/math.d
|
@ -3500,7 +3500,8 @@ real modf(real x, ref real i) @trusted nothrow @nogc
|
|||
*/
|
||||
real scalbn(real x, int n) @trusted nothrow @nogc
|
||||
{
|
||||
version(InlineAsm_X86_Any) {
|
||||
version(InlineAsm_X86_Any)
|
||||
{
|
||||
// scalbnl is not supported on DMD-Windows, so use asm pure nothrow @nogc.
|
||||
version (Win64)
|
||||
{
|
||||
|
@ -4393,7 +4394,8 @@ private:
|
|||
}
|
||||
}
|
||||
public:
|
||||
version (IeeeFlagsSupport) {
|
||||
version (IeeeFlagsSupport)
|
||||
{
|
||||
|
||||
/// The result cannot be represented exactly, so rounding occurred.
|
||||
/// (example: x = sin(0.1); )
|
||||
|
@ -6033,7 +6035,8 @@ typeof(Unqual!(F).init * Unqual!(G).init) pow(F, G)(F x, G n) @nogc @trusted pur
|
|||
default:
|
||||
v = x;
|
||||
p = 1;
|
||||
while (1){
|
||||
while (1)
|
||||
{
|
||||
if (m & 1)
|
||||
p *= v;
|
||||
m >>= 1;
|
||||
|
@ -6722,7 +6725,8 @@ body
|
|||
assert(poly(x, pp) == y);
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
static assert(poly(3.0, [1.0, 2.0, 3.0]) == 34);
|
||||
}
|
||||
|
||||
|
|
|
@ -128,13 +128,15 @@ real sgnGamma(real x)
|
|||
return real.nan;
|
||||
}
|
||||
long n = rndtol(x);
|
||||
if (x == n) {
|
||||
if (x == n)
|
||||
{
|
||||
return x == 0 ? copysign(1, x) : real.nan;
|
||||
}
|
||||
return n & 1 ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
assert(sgnGamma(5.0) == 1.0);
|
||||
assert(isNaN(sgnGamma(-3.0)));
|
||||
assert(sgnGamma(-0.1) == -1.0);
|
||||
|
@ -151,12 +153,14 @@ unittest {
|
|||
*/
|
||||
real beta(real x, real y)
|
||||
{
|
||||
if ((x+y)> MAXGAMMA) {
|
||||
if ((x+y)> MAXGAMMA)
|
||||
{
|
||||
return exp(logGamma(x) + logGamma(y) - logGamma(x+y));
|
||||
} else return gamma(x) * gamma(y) / gamma(x+y);
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
assert(isIdentical(beta(NaN(0xABC), 4), NaN(0xABC)));
|
||||
assert(isIdentical(beta(2, NaN(0xABC)), NaN(0xABC)));
|
||||
}
|
||||
|
|
51
std/mmfile.d
51
std/mmfile.d
|
@ -141,7 +141,8 @@ class MmFile
|
|||
size_t initial_map = (window && 2*window<size)
|
||||
? 2*window : cast(size_t)size;
|
||||
auto p = mmap(address, initial_map, prot, flags, fd, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
if (p == MAP_FAILED)
|
||||
{
|
||||
errnoEnforce(false, "Could not map file into memory");
|
||||
}
|
||||
data = p[0 .. initial_map];
|
||||
|
@ -501,9 +502,12 @@ class MmFile
|
|||
private void unmap()
|
||||
{
|
||||
debug (MMFILE) printf("MmFile.unmap()\n");
|
||||
version(Windows) {
|
||||
version(Windows)
|
||||
{
|
||||
wenforce(!data.ptr || UnmapViewOfFile(data.ptr) != FALSE, "UnmapViewOfFile");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
errnoEnforce(!data.ptr || munmap(cast(void*)data, data.length) == 0,
|
||||
"munmap failed");
|
||||
}
|
||||
|
@ -517,11 +521,14 @@ class MmFile
|
|||
void* p;
|
||||
if (start+len > size)
|
||||
len = cast(size_t)(size-start);
|
||||
version(Windows) {
|
||||
version(Windows)
|
||||
{
|
||||
uint hi = cast(uint)(start>>32);
|
||||
p = MapViewOfFileEx(hFileMap, dwDesiredAccess, hi, cast(uint)start, len, address);
|
||||
wenforce(p, "MapViewOfFileEx");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
p = mmap(address, len, prot, flags, fd, cast(off_t)start);
|
||||
errnoEnforce(p != MAP_FAILED);
|
||||
}
|
||||
|
@ -533,11 +540,15 @@ class MmFile
|
|||
private void ensureMapped(ulong i)
|
||||
{
|
||||
debug (MMFILE) printf("MmFile.ensureMapped(%lld)\n", i);
|
||||
if (!mapped(i)) {
|
||||
if (!mapped(i))
|
||||
{
|
||||
unmap();
|
||||
if (window == 0) {
|
||||
if (window == 0)
|
||||
{
|
||||
map(0,cast(size_t)size);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong block = i/window;
|
||||
if (block == 0)
|
||||
map(0,2*window);
|
||||
|
@ -551,16 +562,23 @@ class MmFile
|
|||
private void ensureMapped(ulong i, ulong j)
|
||||
{
|
||||
debug (MMFILE) printf("MmFile.ensureMapped(%lld, %lld)\n", i, j);
|
||||
if (!mapped(i) || !mapped(j-1)) {
|
||||
if (!mapped(i) || !mapped(j-1))
|
||||
{
|
||||
unmap();
|
||||
if (window == 0) {
|
||||
if (window == 0)
|
||||
{
|
||||
map(0,cast(size_t)size);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ulong iblock = i/window;
|
||||
ulong jblock = (j-1)/window;
|
||||
if (iblock == 0) {
|
||||
if (iblock == 0)
|
||||
{
|
||||
map(0,cast(size_t)(window*(jblock+2)));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
map(window*(iblock-1),cast(size_t)(window*(jblock-iblock+3)));
|
||||
}
|
||||
}
|
||||
|
@ -619,13 +637,16 @@ unittest
|
|||
|
||||
const size_t K = 1024;
|
||||
size_t win = 64*K; // assume the page size is 64K
|
||||
version(Windows) {
|
||||
version(Windows)
|
||||
{
|
||||
/+ these aren't defined in core.sys.windows.windows so let's use default
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo(&sysinfo);
|
||||
win = sysinfo.dwAllocationGranularity;
|
||||
+/
|
||||
} else version (linux) {
|
||||
}
|
||||
else version (linux)
|
||||
{
|
||||
// getpagesize() is not defined in the unix D headers so use the guess
|
||||
}
|
||||
string test_file = std.file.deleteme ~ "-testing.txt";
|
||||
|
|
|
@ -1022,7 +1022,8 @@ private auto _basicHTTP(T)(const(char)[] url, const(void)[] sendData, HTTP clien
|
|||
client.onReceiveHeader = (in char[] key,
|
||||
in char[] value)
|
||||
{
|
||||
if (key == "content-length") {
|
||||
if (key == "content-length")
|
||||
{
|
||||
import std.conv : to;
|
||||
content.reserve(value.to!size_t);
|
||||
}
|
||||
|
|
|
@ -1215,7 +1215,8 @@ private:
|
|||
tail = task;
|
||||
tail.prev = null;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
assert(tail);
|
||||
task.prev = tail;
|
||||
tail.next = task;
|
||||
|
@ -2740,7 +2741,8 @@ public:
|
|||
{
|
||||
auto filesHandles = new File[taskPool.size + 1];
|
||||
scope(exit) {
|
||||
foreach (ref handle; fileHandles) {
|
||||
foreach (ref handle; fileHandles)
|
||||
{
|
||||
handle.close();
|
||||
}
|
||||
}
|
||||
|
@ -2825,7 +2827,8 @@ public:
|
|||
{
|
||||
return num;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return ((num / cacheLineSize) + 1) * cacheLineSize;
|
||||
}
|
||||
}
|
||||
|
@ -3299,7 +3302,8 @@ Example:
|
|||
// default TaskPool instance.
|
||||
auto logs = new double[1_000_000];
|
||||
|
||||
foreach (i, ref elem; parallel(logs)) {
|
||||
foreach (i, ref elem; parallel(logs))
|
||||
{
|
||||
elem = log(i + 1.0);
|
||||
}
|
||||
---
|
||||
|
|
|
@ -179,7 +179,8 @@ interface RandomAccessFinite(E) : BidirectionalRange!(E) {
|
|||
|
||||
// Can't support slicing until issues with requiring slicing for all
|
||||
// finite random access ranges are fully resolved.
|
||||
version(none) {
|
||||
version(none)
|
||||
{
|
||||
///
|
||||
RandomAccessFinite!E opSlice(size_t, size_t);
|
||||
}
|
||||
|
@ -277,30 +278,51 @@ class OutputRangeObject(R, E...) : staticMap!(OutputRange, E) {
|
|||
template MostDerivedInputRange(R) if (isInputRange!(Unqual!R)) {
|
||||
private alias E = ElementType!R;
|
||||
|
||||
static if (isRandomAccessRange!R) {
|
||||
static if (isInfinite!R) {
|
||||
static if (isRandomAccessRange!R)
|
||||
{
|
||||
static if (isInfinite!R)
|
||||
{
|
||||
alias MostDerivedInputRange = RandomAccessInfinite!E;
|
||||
} else static if (hasAssignableElements!R) {
|
||||
}
|
||||
else static if (hasAssignableElements!R)
|
||||
{
|
||||
alias MostDerivedInputRange = RandomFiniteAssignable!E;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
alias MostDerivedInputRange = RandomAccessFinite!E;
|
||||
}
|
||||
} else static if (isBidirectionalRange!R) {
|
||||
static if (hasAssignableElements!R) {
|
||||
}
|
||||
else static if (isBidirectionalRange!R)
|
||||
{
|
||||
static if (hasAssignableElements!R)
|
||||
{
|
||||
alias MostDerivedInputRange = BidirectionalAssignable!E;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
alias MostDerivedInputRange = BidirectionalRange!E;
|
||||
}
|
||||
} else static if (isForwardRange!R) {
|
||||
static if (hasAssignableElements!R) {
|
||||
}
|
||||
else static if (isForwardRange!R)
|
||||
{
|
||||
static if (hasAssignableElements!R)
|
||||
{
|
||||
alias MostDerivedInputRange = ForwardAssignable!E;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
alias MostDerivedInputRange = ForwardRange!E;
|
||||
}
|
||||
} else {
|
||||
static if (hasAssignableElements!R) {
|
||||
}
|
||||
else
|
||||
{
|
||||
static if (hasAssignableElements!R)
|
||||
{
|
||||
alias MostDerivedInputRange = InputAssignable!E;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
alias MostDerivedInputRange = InputRange!E;
|
||||
}
|
||||
}
|
||||
|
@ -311,11 +333,16 @@ template MostDerivedInputRange(R) if (isInputRange!(Unqual!R)) {
|
|||
* derived from the $(D InputRange) interface, aliases itself away.
|
||||
*/
|
||||
template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
||||
static if (is(R : InputRange!(ElementType!R))) {
|
||||
static if (is(R : InputRange!(ElementType!R)))
|
||||
{
|
||||
alias InputRangeObject = R;
|
||||
} else static if (!is(Unqual!R == R)) {
|
||||
}
|
||||
else static if (!is(Unqual!R == R))
|
||||
{
|
||||
alias InputRangeObject = InputRangeObject!(Unqual!R);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
///
|
||||
class InputRangeObject : MostDerivedInputRange!(R) {
|
||||
|
@ -335,19 +362,22 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
void popFront() { _range.popFront(); }
|
||||
@property bool empty() { return _range.empty; }
|
||||
|
||||
static if (isForwardRange!R) {
|
||||
static if (isForwardRange!R)
|
||||
{
|
||||
@property typeof(this) save() {
|
||||
return new typeof(this)(_range.save);
|
||||
}
|
||||
}
|
||||
|
||||
static if (hasAssignableElements!R) {
|
||||
static if (hasAssignableElements!R)
|
||||
{
|
||||
@property void front(E newVal) {
|
||||
_range.front = newVal;
|
||||
}
|
||||
}
|
||||
|
||||
static if (isBidirectionalRange!R) {
|
||||
static if (isBidirectionalRange!R)
|
||||
{
|
||||
@property E back() { return _range.back; }
|
||||
|
||||
E moveBack() {
|
||||
|
@ -356,14 +386,16 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
|
||||
void popBack() { return _range.popBack(); }
|
||||
|
||||
static if (hasAssignableElements!R) {
|
||||
static if (hasAssignableElements!R)
|
||||
{
|
||||
@property void back(E newVal) {
|
||||
_range.back = newVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static if (isRandomAccessRange!R) {
|
||||
static if (isRandomAccessRange!R)
|
||||
{
|
||||
E opIndex(size_t index) {
|
||||
return _range[index];
|
||||
}
|
||||
|
@ -372,13 +404,15 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
return _range.moveAt(index);
|
||||
}
|
||||
|
||||
static if (hasAssignableElements!R) {
|
||||
static if (hasAssignableElements!R)
|
||||
{
|
||||
void opIndexAssign(E val, size_t index) {
|
||||
_range[index] = val;
|
||||
}
|
||||
}
|
||||
|
||||
static if (!isInfinite!R) {
|
||||
static if (!isInfinite!R)
|
||||
{
|
||||
@property size_t length() {
|
||||
return _range.length;
|
||||
}
|
||||
|
@ -388,7 +422,8 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
// Can't support slicing until all the issues with
|
||||
// requiring slicing support for finite random access
|
||||
// ranges are resolved.
|
||||
version(none) {
|
||||
version(none)
|
||||
{
|
||||
typeof(this) opSlice(size_t lower, size_t upper) {
|
||||
return new typeof(this)(_range[lower..upper]);
|
||||
}
|
||||
|
@ -401,7 +436,8 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
int opApply(int delegate(E) dg) {
|
||||
int res;
|
||||
|
||||
for (auto r = _range; !r.empty; r.popFront()) {
|
||||
for (auto r = _range; !r.empty; r.popFront())
|
||||
{
|
||||
res = dg(r.front);
|
||||
if (res) break;
|
||||
}
|
||||
|
@ -413,7 +449,8 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
int res;
|
||||
|
||||
size_t i = 0;
|
||||
for (auto r = _range; !r.empty; r.popFront()) {
|
||||
for (auto r = _range; !r.empty; r.popFront())
|
||||
{
|
||||
res = dg(i, r.front);
|
||||
if (res) break;
|
||||
i++;
|
||||
|
@ -429,9 +466,12 @@ template InputRangeObject(R) if (isInputRange!(Unqual!R)) {
|
|||
* See $(LREF InputRange) for an example.
|
||||
*/
|
||||
InputRangeObject!R inputRangeObject(R)(R range) if (isInputRange!R) {
|
||||
static if (is(R : InputRange!(ElementType!R))) {
|
||||
static if (is(R : InputRange!(ElementType!R)))
|
||||
{
|
||||
return range;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return new InputRangeObject!R(range);
|
||||
}
|
||||
}
|
||||
|
@ -483,7 +523,8 @@ unittest
|
|||
|
||||
assert(inputRangeObject(arrWrapped) is arrWrapped);
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
auto d = DummyType.init;
|
||||
static assert(propagatesRangeType!(DummyType,
|
||||
typeof(inputRangeObject(d))));
|
||||
|
|
|
@ -349,10 +349,14 @@ if (isBidirectionalRange!(Unqual!Range))
|
|||
{
|
||||
import std.internal.test.dummyrange;
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
static if (!isBidirectionalRange!DummyType) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
static if (!isBidirectionalRange!DummyType)
|
||||
{
|
||||
static assert(!__traits(compiles, Retro!DummyType));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
DummyType dummyRange;
|
||||
dummyRange.reinit();
|
||||
|
||||
|
@ -363,11 +367,13 @@ if (isBidirectionalRange!(Unqual!Range))
|
|||
assert(myRetro.moveFront() == 10);
|
||||
assert(myRetro.moveBack() == 1);
|
||||
|
||||
static if (isRandomAccessRange!DummyType && hasLength!DummyType) {
|
||||
static if (isRandomAccessRange!DummyType && hasLength!DummyType)
|
||||
{
|
||||
assert(myRetro[0] == myRetro.front);
|
||||
assert(myRetro.moveAt(2) == 8);
|
||||
|
||||
static if (DummyType.r == ReturnBy.Reference) {
|
||||
static if (DummyType.r == ReturnBy.Reference)
|
||||
{
|
||||
{
|
||||
myRetro[9]++;
|
||||
scope(exit) myRetro[9]--;
|
||||
|
@ -689,7 +695,8 @@ debug unittest
|
|||
// Check for infiniteness propagation.
|
||||
static assert(isInfinite!(typeof(stride(repeat(1), 3))));
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
DummyType dummyRange;
|
||||
dummyRange.reinit();
|
||||
|
||||
|
@ -697,23 +704,27 @@ debug unittest
|
|||
|
||||
// Should fail if no length and bidirectional b/c there's no way
|
||||
// to know how much slack we have.
|
||||
static if (hasLength!DummyType || !isBidirectionalRange!DummyType) {
|
||||
static if (hasLength!DummyType || !isBidirectionalRange!DummyType)
|
||||
{
|
||||
static assert(propagatesRangeType!(typeof(myStride), DummyType));
|
||||
}
|
||||
assert(myStride.front == 1);
|
||||
assert(myStride.moveFront() == 1);
|
||||
assert(equal(myStride, [1, 5, 9]));
|
||||
|
||||
static if (hasLength!DummyType) {
|
||||
static if (hasLength!DummyType)
|
||||
{
|
||||
assert(myStride.length == 3);
|
||||
}
|
||||
|
||||
static if (isBidirectionalRange!DummyType && hasLength!DummyType) {
|
||||
static if (isBidirectionalRange!DummyType && hasLength!DummyType)
|
||||
{
|
||||
assert(myStride.back == 9);
|
||||
assert(myStride.moveBack() == 9);
|
||||
}
|
||||
|
||||
static if (isRandomAccessRange!DummyType && hasLength!DummyType) {
|
||||
static if (isRandomAccessRange!DummyType && hasLength!DummyType)
|
||||
{
|
||||
assert(myStride[0] == 1);
|
||||
assert(myStride[1] == 5);
|
||||
assert(myStride.moveAt(1) == 5);
|
||||
|
@ -722,7 +733,8 @@ debug unittest
|
|||
static assert(hasSlicing!(typeof(myStride)));
|
||||
}
|
||||
|
||||
static if (DummyType.r == ReturnBy.Reference) {
|
||||
static if (DummyType.r == ReturnBy.Reference)
|
||||
{
|
||||
// Make sure reference is propagated.
|
||||
|
||||
{
|
||||
|
@ -736,7 +748,8 @@ debug unittest
|
|||
assert(dummyRange.front == 4);
|
||||
}
|
||||
|
||||
static if (isBidirectionalRange!DummyType && hasLength!DummyType) {
|
||||
static if (isBidirectionalRange!DummyType && hasLength!DummyType)
|
||||
{
|
||||
{
|
||||
myStride.back++;
|
||||
scope(exit) myStride.back--;
|
||||
|
@ -748,7 +761,8 @@ debug unittest
|
|||
assert(myStride.back == 111);
|
||||
}
|
||||
|
||||
static if (isRandomAccessRange!DummyType) {
|
||||
static if (isRandomAccessRange!DummyType)
|
||||
{
|
||||
{
|
||||
myStride[1]++;
|
||||
scope(exit) myStride[1]--;
|
||||
|
@ -1172,9 +1186,11 @@ unittest
|
|||
// Check that chain at least instantiates and compiles with every possible
|
||||
// pair of DummyRange types, in either order.
|
||||
|
||||
foreach (DummyType1; AllDummyRanges) {
|
||||
foreach (DummyType1; AllDummyRanges)
|
||||
{
|
||||
DummyType1 dummy1;
|
||||
foreach (DummyType2; AllDummyRanges) {
|
||||
foreach (DummyType2; AllDummyRanges)
|
||||
{
|
||||
DummyType2 dummy2;
|
||||
auto myChain = chain(dummy1, dummy2);
|
||||
|
||||
|
@ -1183,7 +1199,8 @@ unittest
|
|||
);
|
||||
|
||||
assert(myChain.front == 1);
|
||||
foreach (i; 0..dummyLength) {
|
||||
foreach (i; 0..dummyLength)
|
||||
{
|
||||
myChain.popFront();
|
||||
}
|
||||
assert(myChain.front == 1);
|
||||
|
@ -2030,18 +2047,22 @@ if (isInputRange!(Unqual!R) && (isInfinite!(Unqual!R) || !hasSlicing!(Unqual!R)
|
|||
takeMyStrAgain = take(takeMyStr, 10);
|
||||
assert(equal(takeMyStrAgain, "This is"));
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
DummyType dummy;
|
||||
auto t = take(dummy, 5);
|
||||
alias T = typeof(t);
|
||||
|
||||
static if (isRandomAccessRange!DummyType) {
|
||||
static if (isRandomAccessRange!DummyType)
|
||||
{
|
||||
static assert(isRandomAccessRange!T);
|
||||
assert(t[4] == 5);
|
||||
|
||||
assert(moveAt(t, 1) == t[1]);
|
||||
assert(t.back == moveBack(t));
|
||||
} else static if (isForwardRange!DummyType) {
|
||||
}
|
||||
else static if (isForwardRange!DummyType)
|
||||
{
|
||||
static assert(isForwardRange!T);
|
||||
}
|
||||
|
||||
|
@ -4011,7 +4032,8 @@ unittest
|
|||
|
||||
alias FOO = Zip!(immutable(int)[], immutable(float)[]);
|
||||
|
||||
foreach (t; stuff.expand) {
|
||||
foreach (t; stuff.expand)
|
||||
{
|
||||
auto arr1 = t[0];
|
||||
auto arr2 = t[1];
|
||||
auto zShortest = zip(arr1, arr2);
|
||||
|
@ -4052,15 +4074,18 @@ unittest
|
|||
// make -fwin32.mak unittest makes the compiler completely run out of RAM.
|
||||
// You need to test just this module.
|
||||
/+
|
||||
foreach (DummyType1; AllDummyRanges) {
|
||||
foreach (DummyType1; AllDummyRanges)
|
||||
{
|
||||
DummyType1 d1;
|
||||
foreach (DummyType2; AllDummyRanges) {
|
||||
foreach (DummyType2; AllDummyRanges)
|
||||
{
|
||||
DummyType2 d2;
|
||||
auto r = zip(d1, d2);
|
||||
assert(equal(map!"a[0]"(r), [1,2,3,4,5,6,7,8,9,10]));
|
||||
assert(equal(map!"a[1]"(r), [1,2,3,4,5,6,7,8,9,10]));
|
||||
|
||||
static if (isForwardRange!DummyType1 && isForwardRange!DummyType2) {
|
||||
static if (isForwardRange!DummyType1 && isForwardRange!DummyType2)
|
||||
{
|
||||
static assert(isForwardRange!(typeof(r)));
|
||||
}
|
||||
|
||||
|
@ -4401,7 +4426,8 @@ unittest
|
|||
uint[] res1;
|
||||
float[] res2;
|
||||
|
||||
foreach (a, ref b; l) {
|
||||
foreach (a, ref b; l)
|
||||
{
|
||||
res1 ~= a;
|
||||
res2 ~= b;
|
||||
}
|
||||
|
@ -4760,7 +4786,8 @@ auto sequence(alias fun, State...)(State args)
|
|||
|
||||
auto odds = Sequence!("a[0] + n * a[1]", Tuple!(int, int))(
|
||||
tuple(1, 2));
|
||||
for (int currentOdd = 1; currentOdd <= 21; currentOdd += 2) {
|
||||
for (int currentOdd = 1; currentOdd <= 21; currentOdd += 2)
|
||||
{
|
||||
assert(odds.front == odds[0]);
|
||||
assert(odds[0] == currentOdd);
|
||||
odds.popFront();
|
||||
|
@ -5671,17 +5698,20 @@ FrontTransversal!(RangeOfRanges, opt) frontTransversal(
|
|||
|
||||
static assert(is(FrontTransversal!(immutable int[][])));
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
auto dummies =
|
||||
[DummyType.init, DummyType.init, DummyType.init, DummyType.init];
|
||||
|
||||
foreach (i, ref elem; dummies) {
|
||||
foreach (i, ref elem; dummies)
|
||||
{
|
||||
// Just violate the DummyRange abstraction to get what I want.
|
||||
elem.arr = elem.arr[i..$ - (3 - i)];
|
||||
}
|
||||
|
||||
auto ft = frontTransversal!(TransverseOptions.assumeNotJagged)(dummies);
|
||||
static if (isForwardRange!DummyType) {
|
||||
static if (isForwardRange!DummyType)
|
||||
{
|
||||
static assert(isForwardRange!(typeof(ft)));
|
||||
}
|
||||
|
||||
|
@ -5699,7 +5729,8 @@ FrontTransversal!(RangeOfRanges, opt) frontTransversal(
|
|||
// Test infiniteness propagation.
|
||||
static assert(isInfinite!(typeof(frontTransversal(repeat("foo")))));
|
||||
|
||||
static if (DummyType.r == ReturnBy.Reference) {
|
||||
static if (DummyType.r == ReturnBy.Reference)
|
||||
{
|
||||
{
|
||||
ft.front++;
|
||||
scope(exit) ft.front--;
|
||||
|
@ -6004,7 +6035,8 @@ Transversal!(RangeOfRanges, opt) transversal
|
|||
// Test w/o ref return.
|
||||
alias D = DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Random);
|
||||
auto drs = [D.init, D.init];
|
||||
foreach (num; 0..10) {
|
||||
foreach (num; 0..10)
|
||||
{
|
||||
auto t = transversal!(TransverseOptions.enforceNotJagged)(drs, num);
|
||||
assert(t[0] == t[1]);
|
||||
assert(t[1] == num + 1);
|
||||
|
|
|
@ -1854,14 +1854,21 @@ void popBackExactly(Range)(ref Range r, size_t n)
|
|||
*/
|
||||
ElementType!R moveFront(R)(R r)
|
||||
{
|
||||
static if (is(typeof(&r.moveFront))) {
|
||||
static if (is(typeof(&r.moveFront)))
|
||||
{
|
||||
return r.moveFront();
|
||||
} else static if (!hasElaborateCopyConstructor!(ElementType!R)) {
|
||||
}
|
||||
else static if (!hasElaborateCopyConstructor!(ElementType!R))
|
||||
{
|
||||
return r.front;
|
||||
} else static if (is(typeof(&(r.front())) == ElementType!R*)) {
|
||||
}
|
||||
else static if (is(typeof(&(r.front())) == ElementType!R*))
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
return move(r.front);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
static assert(0,
|
||||
"Cannot move front of a range with a postblit and an rvalue front.");
|
||||
}
|
||||
|
@ -1905,14 +1912,21 @@ ElementType!R moveFront(R)(R r)
|
|||
*/
|
||||
ElementType!R moveBack(R)(R r)
|
||||
{
|
||||
static if (is(typeof(&r.moveBack))) {
|
||||
static if (is(typeof(&r.moveBack)))
|
||||
{
|
||||
return r.moveBack();
|
||||
} else static if (!hasElaborateCopyConstructor!(ElementType!R)) {
|
||||
}
|
||||
else static if (!hasElaborateCopyConstructor!(ElementType!R))
|
||||
{
|
||||
return r.back;
|
||||
} else static if (is(typeof(&(r.back())) == ElementType!R*)) {
|
||||
}
|
||||
else static if (is(typeof(&(r.back())) == ElementType!R*))
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
return move(r.back);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
static assert(0,
|
||||
"Cannot move back of a range with a postblit and an rvalue back.");
|
||||
}
|
||||
|
@ -1944,14 +1958,21 @@ ElementType!R moveBack(R)(R r)
|
|||
*/
|
||||
ElementType!R moveAt(R)(R r, size_t i)
|
||||
{
|
||||
static if (is(typeof(&r.moveAt))) {
|
||||
static if (is(typeof(&r.moveAt)))
|
||||
{
|
||||
return r.moveAt(i);
|
||||
} else static if (!hasElaborateCopyConstructor!(ElementType!(R))) {
|
||||
}
|
||||
else static if (!hasElaborateCopyConstructor!(ElementType!(R)))
|
||||
{
|
||||
return r[i];
|
||||
} else static if (is(typeof(&r[i]) == ElementType!R*)) {
|
||||
}
|
||||
else static if (is(typeof(&r[i]) == ElementType!R*))
|
||||
{
|
||||
import std.algorithm.mutation : move;
|
||||
return move(r[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
static assert(0,
|
||||
"Cannot move element of a range with a postblit and rvalue elements.");
|
||||
}
|
||||
|
@ -1971,15 +1992,18 @@ ElementType!R moveAt(R)(R r, size_t i)
|
|||
{
|
||||
import std.internal.test.dummyrange;
|
||||
|
||||
foreach (DummyType; AllDummyRanges) {
|
||||
foreach (DummyType; AllDummyRanges)
|
||||
{
|
||||
auto d = DummyType.init;
|
||||
assert(moveFront(d) == 1);
|
||||
|
||||
static if (isBidirectionalRange!DummyType) {
|
||||
static if (isBidirectionalRange!DummyType)
|
||||
{
|
||||
assert(moveBack(d) == 10);
|
||||
}
|
||||
|
||||
static if (isRandomAccessRange!DummyType) {
|
||||
static if (isRandomAccessRange!DummyType)
|
||||
{
|
||||
assert(moveAt(d, 2) == 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,8 @@ static assert (IRL!(IR.LookaheadStart) == 3);
|
|||
|
||||
//how many parameters follow the IR, should be optimized fixing some IR bits
|
||||
int immediateParamsIR(IR i){
|
||||
switch (i){
|
||||
switch (i)
|
||||
{
|
||||
case IR.OrEnd,IR.InfiniteEnd,IR.InfiniteQEnd:
|
||||
return 1; // merge table index
|
||||
case IR.InfiniteBloomEnd:
|
||||
|
@ -740,7 +741,8 @@ struct BitTable {
|
|||
uint[4] filter;
|
||||
|
||||
this(CodepointSet set){
|
||||
foreach (iv; set.byInterval){
|
||||
foreach (iv; set.byInterval)
|
||||
{
|
||||
foreach (v; iv.a..iv.b)
|
||||
add(v);
|
||||
}
|
||||
|
|
|
@ -136,7 +136,8 @@ public:
|
|||
ulong hash(uint[] tab)
|
||||
{
|
||||
ulong h = 0xcbf29ce484222325;
|
||||
foreach (v; tab){
|
||||
foreach (v; tab)
|
||||
{
|
||||
h ^= v;
|
||||
h *= 0x100000001b3;
|
||||
}
|
||||
|
|
|
@ -617,7 +617,8 @@ unittest
|
|||
//issue 4574
|
||||
//empty successful match still advances the input
|
||||
string[] pres, posts, hits;
|
||||
foreach (m; matchFn("abcabc", regex("","g"))) {
|
||||
foreach (m; matchFn("abcabc", regex("","g")))
|
||||
{
|
||||
pres ~= m.pre;
|
||||
posts ~= m.post;
|
||||
assert(m.hit.empty);
|
||||
|
@ -719,7 +720,8 @@ unittest
|
|||
auto w2 = ["", "abc", "de", "fg", "hi"];
|
||||
|
||||
uint cnt;
|
||||
foreach (e; sp2) {
|
||||
foreach (e; sp2)
|
||||
{
|
||||
assert(w2[cnt++] == e);
|
||||
}
|
||||
assert(equal(sp2, w2));
|
||||
|
|
|
@ -329,7 +329,8 @@ public alias StaticRegex(Char) = std.regex.internal.ir.StaticRegex!(Char);
|
|||
if (patterns.length > 1)
|
||||
{
|
||||
auto app = appender!S();
|
||||
foreach (i, p; patterns){
|
||||
foreach (i, p; patterns)
|
||||
{
|
||||
if (i != 0)
|
||||
app.put("|");
|
||||
app.put("(?:");
|
||||
|
|
|
@ -351,7 +351,8 @@ unittest
|
|||
a.value = 7;
|
||||
}
|
||||
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
class Observer
|
||||
{
|
||||
int i;
|
||||
|
|
12
std/socket.d
12
std/socket.d
|
@ -3027,7 +3027,9 @@ public:
|
|||
return buf.length
|
||||
? .recv(sock, buf.ptr, capToInt(buf.length), cast(int)flags)
|
||||
: 0;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return buf.length
|
||||
? .recv(sock, buf.ptr, buf.length, cast(int)flags)
|
||||
: 0;
|
||||
|
@ -3060,7 +3062,9 @@ public:
|
|||
assert(from.addressFamily == _family);
|
||||
// if (!read) //connection closed
|
||||
return read;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
auto read = .recvfrom(sock, buf.ptr, buf.length, cast(int)flags, from.name, &nameLen);
|
||||
assert(from.addressFamily == _family);
|
||||
// if (!read) //connection closed
|
||||
|
@ -3087,7 +3091,9 @@ public:
|
|||
auto read = .recvfrom(sock, buf.ptr, capToInt(buf.length), cast(int)flags, null, null);
|
||||
// if (!read) //connection closed
|
||||
return read;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
auto read = .recvfrom(sock, buf.ptr, buf.length, cast(int)flags, null, null);
|
||||
// if (!read) //connection closed
|
||||
return read;
|
||||
|
|
38
std/stdio.d
38
std/stdio.d
|
@ -1628,11 +1628,16 @@ is recommended if you want to process a complete file.
|
|||
auto last = terminator.back;
|
||||
C[] buf2;
|
||||
swap(buf, buf2);
|
||||
for (;;) {
|
||||
if (!readln(buf2, last) || endsWith(buf2, terminator)) {
|
||||
if (buf.empty) {
|
||||
for (;;)
|
||||
{
|
||||
if (!readln(buf2, last) || endsWith(buf2, terminator))
|
||||
{
|
||||
if (buf.empty)
|
||||
{
|
||||
buf = buf2;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
buf ~= buf2;
|
||||
}
|
||||
break;
|
||||
|
@ -3950,7 +3955,8 @@ unittest
|
|||
alias TestedWith =
|
||||
AliasSeq!(string, wstring, dstring,
|
||||
char[], wchar[], dchar[]);
|
||||
foreach (T; TestedWith) {
|
||||
foreach (T; TestedWith)
|
||||
{
|
||||
// test looping with an empty file
|
||||
std.file.write(deleteme, "");
|
||||
auto f = File(deleteme, "r");
|
||||
|
@ -3991,7 +3997,8 @@ unittest
|
|||
|
||||
// test with ubyte[] inputs
|
||||
alias TestedWith2 = AliasSeq!(immutable(ubyte)[], ubyte[]);
|
||||
foreach (T; TestedWith2) {
|
||||
foreach (T; TestedWith2)
|
||||
{
|
||||
// test looping with an empty file
|
||||
std.file.write(deleteme, "");
|
||||
auto f = File(deleteme, "r");
|
||||
|
@ -4124,9 +4131,12 @@ private struct ChunksImpl
|
|||
if (!f.eof) throw new StdioException(null);
|
||||
buffer.length = r;
|
||||
}
|
||||
static if (is(typeof(dg(tally, buffer)))) {
|
||||
static if (is(typeof(dg(tally, buffer))))
|
||||
{
|
||||
if ((result = dg(tally, buffer)) != 0) break;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((result = dg(buffer)) != 0) break;
|
||||
}
|
||||
++tally;
|
||||
|
@ -4451,9 +4461,11 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
|
|||
*/
|
||||
L1:
|
||||
int c;
|
||||
while ((c = FGETC(fp)) != -1) {
|
||||
while ((c = FGETC(fp)) != -1)
|
||||
{
|
||||
app.putchar(cast(char) c);
|
||||
if (c == terminator) {
|
||||
if (c == terminator)
|
||||
{
|
||||
buf = app.data;
|
||||
return buf.length;
|
||||
}
|
||||
|
@ -4535,9 +4547,11 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
|
|||
app.initialize(buf);
|
||||
|
||||
int c;
|
||||
while ((c = FGETC(fp)) != -1) {
|
||||
while ((c = FGETC(fp)) != -1)
|
||||
{
|
||||
app.putchar(cast(char) c);
|
||||
if (c == terminator) {
|
||||
if (c == terminator)
|
||||
{
|
||||
buf = app.data;
|
||||
return buf.length;
|
||||
}
|
||||
|
|
575
std/stream.d
575
std/stream.d
File diff suppressed because it is too large
Load diff
10
std/traits.d
10
std/traits.d
|
@ -970,7 +970,8 @@ template arity(alias func)
|
|||
}
|
||||
|
||||
///
|
||||
unittest {
|
||||
unittest
|
||||
{
|
||||
void foo(){}
|
||||
static assert(arity!foo==0);
|
||||
void bar(uint){}
|
||||
|
@ -6739,9 +6740,12 @@ template getUDAs(alias symbol, alias attribute)
|
|||
import std.typetuple : Filter;
|
||||
|
||||
template isDesiredUDA(alias S) {
|
||||
static if (__traits(compiles, is(typeof(S) == attribute))) {
|
||||
static if (__traits(compiles, is(typeof(S) == attribute)))
|
||||
{
|
||||
enum isDesiredUDA = is(typeof(S) == attribute);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
enum isDesiredUDA = isInstanceOf!(attribute, typeof(S));
|
||||
}
|
||||
}
|
||||
|
|
24
std/uni.d
24
std/uni.d
|
@ -5304,7 +5304,8 @@ unittest
|
|||
alias fails8 = AliasSeq!("\xC1", "\x80\x00","\xC0\x00", "\xCF\x79",
|
||||
"\xFF\x00\0x00\0x00\x00", "\xC0\0x80\0x80\x80", "\x80\0x00\0x00\x00",
|
||||
"\xCF\x00\0x00\0x00\x00");
|
||||
foreach (msg; fails8){
|
||||
foreach (msg; fails8)
|
||||
{
|
||||
assert(collectException((){
|
||||
auto s = msg;
|
||||
size_t idx = 0;
|
||||
|
@ -5313,7 +5314,8 @@ unittest
|
|||
}
|
||||
//decode failure cases UTF-16
|
||||
alias fails16 = AliasSeq!([0xD811], [0xDC02]);
|
||||
foreach (msg; fails16){
|
||||
foreach (msg; fails16)
|
||||
{
|
||||
assert(collectException((){
|
||||
auto s = msg.map!(x => cast(wchar)x);
|
||||
utf16.test(s);
|
||||
|
@ -5580,7 +5582,8 @@ unittest
|
|||
auto trie4 = buildTrie!(bool, size_t, max4,
|
||||
sliceBits!(13, 16), sliceBits!(9, 13), sliceBits!(6, 9) , sliceBits!(0, 6)
|
||||
)(redundant4.byInterval);
|
||||
foreach (i; 0..max4){
|
||||
foreach (i; 0..max4)
|
||||
{
|
||||
if (i in redundant4)
|
||||
assert(trie4[i], text(cast(uint)i));
|
||||
}
|
||||
|
@ -5899,7 +5902,8 @@ else
|
|||
target |= asSet(uniProps.So);
|
||||
target |= asSet(uniProps.Po);
|
||||
}
|
||||
else if (ucmp(name, "graphical") == 0){
|
||||
else if (ucmp(name, "graphical") == 0)
|
||||
{
|
||||
target = asSet(uniProps.Alphabetic);
|
||||
|
||||
target |= asSet(uniProps.Mn);
|
||||
|
@ -7287,7 +7291,8 @@ ubyte combiningClass(dchar ch) @safe pure nothrow @nogc
|
|||
}
|
||||
|
||||
///
|
||||
unittest{
|
||||
unittest
|
||||
{
|
||||
// shorten the code
|
||||
alias CC = combiningClass;
|
||||
|
||||
|
@ -7362,7 +7367,8 @@ public dchar compose(dchar first, dchar second) pure nothrow
|
|||
}
|
||||
|
||||
///
|
||||
unittest{
|
||||
unittest
|
||||
{
|
||||
assert(compose('A','\u0308') == '\u00C4');
|
||||
assert(compose('A', 'B') == dchar.init);
|
||||
assert(compose('C', '\u0301') == '\u0106');
|
||||
|
@ -7780,14 +7786,16 @@ private size_t recompose(size_t start, dchar[] input, ubyte[] ccc) pure nothrow
|
|||
// current was merged so its CCC shouldn't affect
|
||||
// composing with the next one
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// if it was a starter then accumCC is now 0, end of loop
|
||||
accumCC = curCC;
|
||||
if (accumCC == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
// ditto here
|
||||
accumCC = curCC;
|
||||
if (accumCC == 0)
|
||||
|
|
12
std/uri.d
12
std/uri.d
|
@ -102,7 +102,8 @@ private string URI_Encode(dstring string, uint unescapedSet)
|
|||
char* R2;
|
||||
|
||||
Rsize *= 2;
|
||||
if (Rsize > 1024) {
|
||||
if (Rsize > 1024)
|
||||
{
|
||||
R2 = (new char[Rsize]).ptr;
|
||||
}
|
||||
else
|
||||
|
@ -182,7 +183,8 @@ private string URI_Encode(dstring string, uint unescapedSet)
|
|||
char *R2;
|
||||
|
||||
Rsize = 2 * (Rlen + L * 3);
|
||||
if (Rsize > 1024) {
|
||||
if (Rsize > 1024)
|
||||
{
|
||||
R2 = (new char[Rsize]).ptr;
|
||||
}
|
||||
else
|
||||
|
@ -232,7 +234,8 @@ private dstring URI_Decode(Char)(in Char[] uri, uint reservedSet) if (isSomeChar
|
|||
|
||||
// Preallocate result buffer R guaranteed to be large enough for result
|
||||
auto Rsize = len;
|
||||
if (Rsize > 1024 / dchar.sizeof) {
|
||||
if (Rsize > 1024 / dchar.sizeof)
|
||||
{
|
||||
R = (new dchar[Rsize]).ptr;
|
||||
}
|
||||
else
|
||||
|
@ -428,7 +431,8 @@ ptrdiff_t uriLength(Char)(in Char[] s) if (isSomeChar!Char)
|
|||
if (s.length <= 4)
|
||||
return -1;
|
||||
|
||||
if (s.length > 7 && icmp(s[0 .. 7], "http://") == 0) {
|
||||
if (s.length > 7 && icmp(s[0 .. 7], "http://") == 0)
|
||||
{
|
||||
i = 7;
|
||||
}
|
||||
else
|
||||
|
|
20
std/zlib.d
20
std/zlib.d
|
@ -686,31 +686,39 @@ unittest // by Dave
|
|||
|
||||
|
||||
// smallish buffers
|
||||
for (int idx = 0; idx < 25; idx++) {
|
||||
for (int idx = 0; idx < 25; idx++)
|
||||
{
|
||||
char[] buf = new char[uniform(0, 100)];
|
||||
|
||||
// Alternate between more & less compressible
|
||||
foreach (ref char c; buf)
|
||||
c = cast(char) (' ' + (uniform(0, idx % 2 ? 91 : 2)));
|
||||
|
||||
if (CompressThenUncompress(buf)) {
|
||||
if (CompressThenUncompress(buf))
|
||||
{
|
||||
debug(zlib) writeln("; Success.");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// larger buffers
|
||||
for (int idx = 0; idx < 25; idx++) {
|
||||
for (int idx = 0; idx < 25; idx++)
|
||||
{
|
||||
char[] buf = new char[uniform(0, 1000/*0000*/)];
|
||||
|
||||
// Alternate between more & less compressible
|
||||
foreach (ref char c; buf)
|
||||
c = cast(char) (' ' + (uniform(0, idx % 2 ? 91 : 10)));
|
||||
|
||||
if (CompressThenUncompress(buf)) {
|
||||
if (CompressThenUncompress(buf))
|
||||
{
|
||||
debug(zlib) writefln("; Success.");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue