Skip to content

Commit

Permalink
rework and try to fix Issue 6586
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Feb 26, 2015
1 parent 71aab20 commit 09ebc58
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions std/math.d
Expand Up @@ -374,7 +374,7 @@ else
// Common code for math implementations.

// Helper for floor/ceil
T floorImpl(T)(T x) @trusted pure nothrow @nogc
T floorImpl(T)(const T x) @trusted pure nothrow @nogc
{
alias F = floatTraits!(T);
// Take care not to trigger library calls from the compiler,
Expand Down Expand Up @@ -2178,7 +2178,7 @@ creal expi(real y) @trusted pure nothrow @nogc
* $(TR $(TD $(PLUSMN)$(NAN)) $(TD $(PLUSMN)$(NAN)) $(TD int.min))
* )
*/
T frexp(T)(T value, out int exp) @trusted pure nothrow @nogc
T frexp(T)(const T value, out int exp) @trusted pure nothrow @nogc
if(isFloatingPoint!T)
{
Unqual!T vf = value;
Expand Down Expand Up @@ -2380,7 +2380,7 @@ unittest
{
import std.typetuple, std.typecons;

foreach (T; TypeTuple!(real, double, float, const(real), immutable(double)))
foreach (T; TypeTuple!(real, double, float))
{
Tuple!(T, T, int)[] vals = // x,frexp,exp
[
Expand Down Expand Up @@ -2410,13 +2410,13 @@ unittest

static if (floatTraits!(T).realFormat == RealFormat.ieeeExtended)
{
static T[3][] extendedvals2 = [ // x,frexp,exp
static T[3][] extendedvals = [ // x,frexp,exp
[0x1.a5f1c2eb3fe4efp+73L, 0x1.A5F1C2EB3FE4EFp-1L, 74], // normal
[0x1.fa01712e8f0471ap-1064L, 0x1.fa01712e8f0471ap-1L, -1063],
[T.min_normal, .5, -16381],
[T.min_normal/2.0L, .5, -16382] // subnormal
];
foreach(elem; extendedvals2)
foreach(elem; extendedvals)
{
T x = elem[0];
T e = elem[1];
Expand All @@ -2431,6 +2431,21 @@ unittest
}
}

unittest
{
import std.typetuple: TypeTuple;
void foo() {
foreach (T; TypeTuple!(real, double, float))
{
int exp;
const T a = 1;
immutable T b = 2;
auto c = frexp(a, exp);
auto d = frexp(b, exp);
}
}
}

/******************************************
* Extracts the exponent of x as a signed integral value.
*
Expand Down Expand Up @@ -5400,7 +5415,7 @@ float nextDown(float x) @safe pure nothrow @nogc
* exceptions will be raised if the function value is subnormal, and x is
* not equal to y.
*/
T nextafter(T)(T x, T y) @safe pure nothrow @nogc
T nextafter(T)(const T x, const T y) @safe pure nothrow @nogc
{
if (x == y) return y;
return ((y>x) ? nextUp(x) : nextDown(x));
Expand Down Expand Up @@ -5918,7 +5933,7 @@ Unqual!(Largest!(F, G)) pow(F, G)(F x, G y) @nogc @trusted pure nothrow
* $(TR $(TD any) $(TD $(NAN)) $(TD 0))
* )
*/
int feqrel(X)(X x, X y) @trusted pure nothrow @nogc
int feqrel(X)(const X x, const X y) @trusted pure nothrow @nogc
if (isFloatingPoint!(X))
{
/* Public Domain. Author: Don Clugston, 18 Aug 2005.
Expand Down Expand Up @@ -5948,7 +5963,7 @@ int feqrel(X)(X x, X y) @trusted pure nothrow @nogc
if (x == y)
return X.mant_dig; // ensure diff!=0, cope with INF.

X diff = fabs(x - y);
Unqual!X diff = fabs(x - y);

ushort *pa = cast(ushort *)(&x);
ushort *pb = cast(ushort *)(&y);
Expand Down Expand Up @@ -6057,6 +6072,11 @@ int feqrel(X)(X x, X y) @trusted pure nothrow @nogc
assert(feqrel(F.nan, F.infinity) == 0);
assert(feqrel(F.infinity, -F.infinity) == 0);
assert(feqrel(F.max, -F.max) == 0);


const F Const = 2;
immutable F Immutable = 2;
auto Compiles = feqrel(Const, Immutable);
}

assert(feqrel(7.1824L, 7.1824L) == real.mant_dig);
Expand Down Expand Up @@ -6086,7 +6106,7 @@ package: // Not public yet
* ieeeMean(x, y) = sqrt(x * y).
*
*/
T ieeeMean(T)(T x, T y) @trusted pure nothrow @nogc
T ieeeMean(T)(const T x, const T y) @trusted pure nothrow @nogc
in
{
// both x and y must have the same sign, and must not be NaN.
Expand Down

0 comments on commit 09ebc58

Please sign in to comment.