Skip to content

Commit

Permalink
Fix a test in runnable/test42.d failing for 64-bit reals
Browse files Browse the repository at this point in the history
Seems like the original author thought about ulong.max being 2^64.
How should 2^64-1 be representable in a double with 53 mantissa bits?
  • Loading branch information
kinke committed Oct 5, 2015
1 parent 43c73c1 commit 10c944b
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions test/runnable/test42.d
Original file line number Diff line number Diff line change
Expand Up @@ -1644,26 +1644,22 @@ void test99()

void test100()
{
{
real r = ulong.max;
printf("r = %Lg, ulong.max = %llu\n", r, ulong.max);
ulong d = cast(ulong)r;
printf("d = %llx, ulong.max = %llx\n", d, ulong.max);
assert(d == ulong.max);
}
static if(real.mant_dig == 64)
{
real r = ulong.max - 1;
printf("r = %Lg, ulong.max = %llu\n", r, ulong.max);
ulong d = cast(ulong)r;
printf("d = %llx, ulong.max = %llx\n", d, ulong.max);
assert(d == ulong.max - 1);
}
else static if(real.mant_dig == 53)
{ //can't store ulong.max-1 in double
}
else
static assert(false, "Test not implemented for this platform");
static void check(ulong value)
{
real r = value;
ulong d = cast(ulong)r;
printf("ulong: %llu => real: %Lg => ulong: %llu\n", value, r, d);
assert(d == value);
}

// check biggest power of 2 representable in ulong: 2^63
check(1L << 63);

// check biggest representable uneven number
static if (real.mant_dig >= 64) // > 64: limited by ulong precision
check(ulong.max); // 2^64-1
else
check((1L << real.mant_dig) - 1);
}

/***************************************************/
Expand Down

0 comments on commit 10c944b

Please sign in to comment.