Showing with 58 additions and 43 deletions.
  1. +18 −13 std/math.d
  2. +40 −30 std/stdio.d
31 changes: 18 additions & 13 deletions std/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,9 @@ version (Win64)
version = Win64_DMD_InlineAsm;
}

import core.bitop;
import core.math;
import core.stdc.math;
import std.traits;
static import core.math;
static import core.stdc.math;
import std.traits;// CommonType, isFloatingPoint, isIntegral, isSigned, isUnsigned, Largest, Unqual

version(LDC)
{
Expand Down Expand Up @@ -159,7 +158,7 @@ else version(D_InlineAsm_X86_64)

version(unittest)
{
import core.stdc.stdio;
import core.stdc.stdio : sprintf;

static if (real.sizeof > double.sizeof)
enum uint useDigits = 16;
Expand Down Expand Up @@ -2556,7 +2555,8 @@ unittest

unittest
{
import std.meta, std.typecons;
import std.meta : AliasSeq;
import std.typecons : tuple, Tuple;

foreach (T; AliasSeq!(real, double, float))
{
Expand Down Expand Up @@ -2643,6 +2643,7 @@ unittest
int ilogb(T)(const T x) @trusted pure nothrow @nogc
if (isFloatingPoint!T)
{
import core.bitop : bsr;
alias F = floatTraits!T;

union floatBits
Expand Down Expand Up @@ -2783,6 +2784,7 @@ int ilogb(T)(const T x) @trusted pure nothrow @nogc
int ilogb(T)(const T x) @safe pure nothrow @nogc
if (isIntegral!T && isUnsigned!T)
{
import core.bitop : bsr;
if (x == 0)
return FP_ILOGB0;
else
Expand All @@ -2795,6 +2797,7 @@ int ilogb(T)(const T x) @safe pure nothrow @nogc
int ilogb(T)(const T x) @safe pure nothrow @nogc
if (isIntegral!T && isSigned!T)
{
import std.traits : Unsigned;
// Note: abs(x) can not be used because the return type is not Unsigned and
// the return value would be wrong for x == int.min
Unsigned!T absx = x>=0 ? x : -x;
Expand All @@ -2806,7 +2809,8 @@ alias FP_ILOGBNAN = core.stdc.math.FP_ILOGBNAN;

@trusted nothrow @nogc unittest
{
import std.meta, std.typecons;
import std.meta : AliasSeq;
import std.typecons : Tuple;
foreach (F; AliasSeq!(float, double, real))
{
alias T = Tuple!(F, int);
Expand Down Expand Up @@ -2879,7 +2883,7 @@ float ldexp(float n, int exp) @safe pure nothrow @nogc { return ldexp(cast(real)
///
@nogc @safe pure nothrow unittest
{
import std.meta;
import std.meta : AliasSeq;
foreach (T; AliasSeq!(float, double, real))
{
T r;
Expand Down Expand Up @@ -4900,7 +4904,7 @@ bool isNaN(X)(X x) @nogc @trusted pure nothrow

@safe pure nothrow @nogc unittest
{
import std.meta;
import std.meta : AliasSeq;

foreach (T; AliasSeq!(float, double, real))
{
Expand Down Expand Up @@ -5084,7 +5088,7 @@ bool isSubnormal(X)(X x) @trusted pure nothrow @nogc
///
@safe pure nothrow @nogc unittest
{
import std.meta;
import std.meta : AliasSeq;

foreach (T; AliasSeq!(float, double, real))
{
Expand Down Expand Up @@ -5324,7 +5328,7 @@ R copysign(R, X)(X to, R from) @trusted pure nothrow @nogc

@safe pure nothrow @nogc unittest
{
import std.meta;
import std.meta : AliasSeq;

foreach (X; AliasSeq!(float, double, real, int, long))
{
Expand Down Expand Up @@ -5905,6 +5909,7 @@ real fma(real x, real y, real z) @safe pure nothrow @nogc { return (x * y) + z;
Unqual!F pow(F, G)(F x, G n) @nogc @trusted pure nothrow
if (isFloatingPoint!(F) && isIntegral!(G))
{
import std.traits : Unsigned;
real p = 1.0, v = void;
Unsigned!(Unqual!G) m = n;
if (n < 0)
Expand Down Expand Up @@ -6906,7 +6911,7 @@ private real polyImpl(real x, in real[] A) @trusted pure nothrow @nogc
*/
bool approxEqual(T, U, V)(T lhs, U rhs, V maxRelDiff, V maxAbsDiff = 1e-5)
{
import std.range;
import std.range.primitives : empty, front, isInputRange, popFront;
static if (isInputRange!T)
{
static if (isInputRange!U)
Expand Down Expand Up @@ -7299,7 +7304,7 @@ unittest

unittest
{
import std.meta;
import std.meta : AliasSeq;
foreach (T; AliasSeq!(float, double, real))
{
T[] values = [-cast(T)NaN(20), -cast(T)NaN(10), -T.nan, -T.infinity,
Expand Down
70 changes: 40 additions & 30 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ Authors: $(WEB digitalmars.com, Walter Bright),
module std.stdio;

public import core.stdc.stdio;
import std.typecons;// Flag
import std.stdiobase;
import core.stdc.stddef;// wchar_t
import std.range.primitives;// empty, front, isBidirectionalRange
import std.traits;// Unqual, isSomeChar, isSomeString
import std.algorithm.mutation; // copy
import std.range.primitives;// ElementEncodingType, front, isBidirectionalRange, isInputRange
import std.stdiobase;
import std.traits;// isSomeChar, isSomeString, Unqual
import std.typecons;// Flag


/++
Expand Down Expand Up @@ -278,6 +279,7 @@ public:
import std.conv : text;
import std.exception : enforce;
import std.format : formattedRead;
import std.range.primitives : empty;
import std.string : chomp;

enforce(file.isOpen, "ByRecord: File must be open");
Expand Down Expand Up @@ -461,7 +463,7 @@ file.
*/
void opAssign(File rhs) @safe
{
import std.algorithm : swap;
import std.algorithm.mutation : swap;

swap(this, rhs);
}
Expand Down Expand Up @@ -1247,8 +1249,8 @@ Removes the lock over the specified file segment.
static void runForked(void delegate() code)
{
import core.stdc.stdlib : exit;
import core.sys.posix.unistd;
import core.sys.posix.sys.wait;
import core.sys.posix.sys.wait : wait;
import core.sys.posix.unistd : fork;
int child, status;
if ((child = fork()) == 0)
{
Expand Down Expand Up @@ -1427,7 +1429,7 @@ void main()
unittest
{
static import std.file;
import std.algorithm : equal;
import std.algorithm.comparison : equal;
import std.meta : AliasSeq;

auto deleteme = testFilename();
Expand Down Expand Up @@ -1619,8 +1621,9 @@ is recommended if you want to process a complete file.
if (isSomeChar!C && is(Unqual!C == C) && !is(C == enum) &&
isBidirectionalRange!R && is(typeof(terminator.front == dchar.init)))
{
import std.algorithm : endsWith, swap;
import std.range.primitives : back;
import std.algorithm.mutation : swap;
import std.algorithm.searching : endsWith;
import std.range.primitives : back, empty;

auto last = terminator.back;
C[] buf2;
Expand Down Expand Up @@ -1776,7 +1779,7 @@ Allows to directly use range operations on lines of a file.
struct ByLine(Char, Terminator)
{
private:
import std.typecons;
import std.typecons : RefCounted, RefCountedAutoInitialize;

/* Ref-counting stops the source range's Impl
* from getting out of sync after the range is copied, e.g.
Expand Down Expand Up @@ -1844,7 +1847,8 @@ Allows to directly use range operations on lines of a file.

void popFront()
{
import std.algorithm : endsWith;
import std.algorithm.searching : endsWith;
import std.range.primitives : empty;
assert(file.isOpen);
line = buffer;
file.readln(line, terminator);
Expand Down Expand Up @@ -1972,7 +1976,7 @@ the contents may well have changed).
private struct ByLineCopy(Char, Terminator)
{
private:
import std.typecons;
import std.typecons : RefCounted, RefCountedAutoInitialize;

/* Ref-counting stops the source range's ByLineCopyImpl
* from getting out of sync after the range is copied, e.g.
Expand Down Expand Up @@ -2101,8 +2105,7 @@ $(XREF file,readText)
unittest
{
static import std.file;
import std.algorithm : equal;
import std.range;
import std.algorithm.comparison : equal;

//printf("Entering test at line %d\n", __LINE__);
scope(failure) printf("Failed test at line %d\n", __LINE__);
Expand All @@ -2122,8 +2125,9 @@ $(XREF file,readText)
void test(Terminator)(string txt, in string[] witness,
KeepTerminator kt, Terminator term, bool popFirstLine = false)
{
import std.array : array;
import std.conv : text;
import std.algorithm : sort;
import std.algorithm.sorting : sort;
import std.range.primitives : walkLength;

uint i;
Expand Down Expand Up @@ -2180,8 +2184,8 @@ $(XREF file,readText)

unittest
{
import std.algorithm : equal;
import std.range;
import std.algorithm.comparison : equal;
import std.range : drop, take;

version(Win64)
{
Expand Down Expand Up @@ -2272,6 +2276,7 @@ $(XREF file,readText)
unittest
{
static import std.file;
import std.typecons : tuple;

// prepare test file
auto testFile = testFilename();
Expand Down Expand Up @@ -2315,7 +2320,7 @@ $(XREF file,readText)

this(File file, ubyte[] buffer)
{
import std.exception;
import std.exception : enforce;
enforce(buffer.length, "size must be larger than 0");
file_ = file;
chunk_ = buffer;
Expand Down Expand Up @@ -2682,6 +2687,7 @@ See $(LREF byChunk) for an example.
// the file mode on destruction, it is RefCounted on Windows.
struct BinaryWriterImpl(bool locking)
{
import std.traits : hasIndirections;
private:
FILE* fps;
string name;
Expand Down Expand Up @@ -2827,10 +2833,11 @@ void main()

unittest
{
import std.algorithm : copy, reverse;
import std.algorithm.mutation : reverse;
static import std.file;
import std.exception : collectException;
import std.range : only, retro, put;
import std.range : only, retro;
import std.range.primitives : put;
import std.string : format;

auto deleteme = testFilename();
Expand Down Expand Up @@ -3051,7 +3058,8 @@ unittest
unittest
{
static import std.file;
import std.range;
import std.range : chain, only, repeat;
import std.range.primitives : isOutputRange;

auto deleteme = testFilename();
scope(exit) std.file.remove(deleteme);
Expand Down Expand Up @@ -3123,7 +3131,7 @@ struct LockingTextReader

void opAssign(LockingTextReader r)
{
import std.algorithm : swap;
import std.algorithm.mutation : swap;
swap(this, r);
}

Expand Down Expand Up @@ -3194,7 +3202,8 @@ unittest
unittest // bugzilla 13686
{
static import std.file;
import std.algorithm : equal;
import std.algorithm.comparison : equal;
import std.utf : byDchar;

auto deleteme = testFilename();
std.file.write(deleteme, "Тест");
Expand All @@ -3204,7 +3213,6 @@ unittest // bugzilla 13686
File(deleteme).readf("%s", &s);
assert(s == "Тест");

import std.utf;
auto ltr = LockingTextReader(File(deleteme)).byDchar;
assert(equal(ltr, "Тест".byDchar));
}
Expand Down Expand Up @@ -3321,6 +3329,7 @@ void writeln(T...)(T args)
!isAggregateType!(typeof(args[0])))
{
import std.exception : enforce;
import std.traits : isStaticArray;

// Specialization for strings - a very frequent case
auto w = .trustedStdout.lockingTextWriter();
Expand Down Expand Up @@ -4170,9 +4179,9 @@ en.cppreference.com/w/c/io#Narrow_and_wide_orientation,
orientation).
*/
void toFile(T)(T data, string fileName)
if (is(typeof(std.algorithm.mutation.copy(data, stdout.lockingBinaryWriter))))
if (is(typeof(copy(data, stdout.lockingBinaryWriter))))
{
std.algorithm.mutation.copy(data, File(fileName, "wb").lockingBinaryWriter);
copy(data, File(fileName, "wb").lockingBinaryWriter);
}

unittest
Expand Down Expand Up @@ -4314,8 +4323,6 @@ unittest
// roll our own appender, but with "safe" arrays
private struct ReadlnAppender
{
import core.stdc.string;

char[] buf;
size_t pos;
bool safeAppend = false;
Expand Down Expand Up @@ -4351,6 +4358,7 @@ private struct ReadlnAppender
}
void reserve(size_t n)
{
import core.stdc.string : memcpy;
if (!reserveWithoutAllocating(n))
{
size_t ncap = buf.length * 2 + 128 + n;
Expand Down Expand Up @@ -4378,6 +4386,7 @@ private struct ReadlnAppender
}
void putonly(char[] b)
{
import core.stdc.string : memcpy;
assert(pos == 0); // assume this is the only put call
if (reserveWithoutAllocating(b.length))
memcpy(buf.ptr + pos, b.ptr, b.length);
Expand Down Expand Up @@ -4689,13 +4698,14 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
}
else version (Posix)
{
import std.utf : encode;
buf.length = 0;
for (int c; (c = FGETWC(fp)) != -1; )
{
if ((c & ~0x7F) == 0)
buf ~= cast(char)c;
else
std.utf.encode(buf, cast(dchar)c);
encode(buf, cast(dchar)c);
if (c == terminator)
break;
}
Expand Down