Skip to content

Commit 7be45e8

Browse files
committed
unittest: Don't run x87 log2 test on 64-bit real targets
1 parent a4d516a commit 7be45e8

File tree

3 files changed

+157
-144
lines changed

3 files changed

+157
-144
lines changed

std/format/internal/floats.d

Lines changed: 101 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,37 +1476,40 @@ if (is(T == float) || is(T == double)
14761476

14771477
assertCTFEable!(
14781478
{
1479-
// log2 is broken for x87-reals on some computers in CTFE
1480-
// the following tests excludes these computers from the tests
1481-
// (https://issues.dlang.org/show_bug.cgi?id=21757)
1482-
enum test = cast(int) log2(3.05e2312L);
1483-
static if (real.mant_dig == 64 && test == 7681)
1479+
static if (real.mant_dig == 64) // 80 bit reals
14841480
{
1485-
auto f = FormatSpec!dchar("");
1486-
f.spec = 'e';
1487-
assert(printFloat(real.infinity, f) == "inf");
1488-
assert(printFloat(10.0L, f) == "1.000000e+01");
1489-
assert(printFloat(2.6080L, f) == "2.608000e+00");
1490-
assert(printFloat(3.05e2312L, f) == "3.050000e+2312");
1491-
1492-
f.precision = 60;
1493-
assert(printFloat(2.65e-54L, f) ==
1494-
"2.650000000000000000059009987400547013941028940935296547599415e-54");
1495-
1496-
/*
1497-
commented out, because CTFE is currently too slow for 5000 digits with extreme values
1498-
1499-
f.precision = 5000;
1500-
auto result2 = printFloat(1.2119e-4822L, f);
1501-
assert(result2.length == 5008);
1502-
assert(result2[$ - 20 .. $] == "60729486595339e-4822");
1503-
auto result3 = printFloat(real.min_normal, f);
1504-
assert(result3.length == 5008);
1505-
assert(result3[$ - 20 .. $] == "20781410082267e-4932");
1506-
auto result4 = printFloat(real.min_normal.nextDown, f);
1507-
assert(result4.length == 5008);
1508-
assert(result4[$ - 20 .. $] == "81413263331006e-4932");
1509-
*/
1481+
// log2 is broken for x87-reals on some computers in CTFE
1482+
// the following tests excludes these computers from the tests
1483+
// (https://issues.dlang.org/show_bug.cgi?id=21757)
1484+
enum test = cast(int) log2(3.05e2312L);
1485+
static if (test == 7681)
1486+
{
1487+
auto f = FormatSpec!dchar("");
1488+
f.spec = 'e';
1489+
assert(printFloat(real.infinity, f) == "inf");
1490+
assert(printFloat(10.0L, f) == "1.000000e+01");
1491+
assert(printFloat(2.6080L, f) == "2.608000e+00");
1492+
assert(printFloat(3.05e2312L, f) == "3.050000e+2312");
1493+
1494+
f.precision = 60;
1495+
assert(printFloat(2.65e-54L, f) ==
1496+
"2.650000000000000000059009987400547013941028940935296547599415e-54");
1497+
1498+
/*
1499+
commented out, because CTFE is currently too slow for 5000 digits with extreme values
1500+
1501+
f.precision = 5000;
1502+
auto result2 = printFloat(1.2119e-4822L, f);
1503+
assert(result2.length == 5008);
1504+
assert(result2[$ - 20 .. $] == "60729486595339e-4822");
1505+
auto result3 = printFloat(real.min_normal, f);
1506+
assert(result3.length == 5008);
1507+
assert(result3[$ - 20 .. $] == "20781410082267e-4932");
1508+
auto result4 = printFloat(real.min_normal.nextDown, f);
1509+
assert(result4.length == 5008);
1510+
assert(result4[$ - 20 .. $] == "81413263331006e-4932");
1511+
*/
1512+
}
15101513
}
15111514
});
15121515
}
@@ -2149,39 +2152,42 @@ if (is(T == float) || is(T == double)
21492152

21502153
assertCTFEable!(
21512154
{
2152-
// log2 is broken for x87-reals on some computers in CTFE
2153-
// the following tests excludes these computers from the tests
2154-
// (https://issues.dlang.org/show_bug.cgi?id=21757)
2155-
enum test = cast(int) log2(3.05e2312L);
2156-
static if (real.mant_dig == 64 && test == 7681)
2155+
static if (real.mant_dig == 64) // 80 bit reals
21572156
{
2158-
auto f = FormatSpec!dchar("");
2159-
f.spec = 'f';
2160-
assert(printFloat(real.infinity, f) == "inf");
2161-
assert(printFloat(10.0L, f) == "10.000000");
2162-
assert(printFloat(2.6080L, f) == "2.608000");
2163-
auto result1 = printFloat(3.05e2312L, f);
2164-
assert(result1.length == 2320);
2165-
assert(result1[0 .. 20] == "30499999999999999999");
2166-
2167-
f.precision = 60;
2168-
assert(printFloat(2.65e-54L, f) ==
2169-
"0.000000000000000000000000000000000000000000000000000002650000");
2170-
2171-
/*
2172-
commented out, because CTFE is currently too slow for 5000 digits with extreme values
2173-
2174-
f.precision = 5000;
2175-
auto result2 = printFloat(1.2119e-4822L, f);
2176-
assert(result2.length == 5002);
2177-
assert(result2[$ - 20 .. $] == "60076763752233836613");
2178-
auto result3 = printFloat(real.min_normal, f);
2179-
assert(result3.length == 5002);
2180-
assert(result3[$ - 20 .. $] == "47124010882722980874");
2181-
auto result4 = printFloat(real.min_normal.nextDown, f);
2182-
assert(result4.length == 5002);
2183-
assert(result4[$ - 20 .. $] == "52925846892214823939");
2184-
*/
2157+
// log2 is broken for x87-reals on some computers in CTFE
2158+
// the following tests excludes these computers from the tests
2159+
// (https://issues.dlang.org/show_bug.cgi?id=21757)
2160+
enum test = cast(int) log2(3.05e2312L);
2161+
static if (test == 7681)
2162+
{
2163+
auto f = FormatSpec!dchar("");
2164+
f.spec = 'f';
2165+
assert(printFloat(real.infinity, f) == "inf");
2166+
assert(printFloat(10.0L, f) == "10.000000");
2167+
assert(printFloat(2.6080L, f) == "2.608000");
2168+
auto result1 = printFloat(3.05e2312L, f);
2169+
assert(result1.length == 2320);
2170+
assert(result1[0 .. 20] == "30499999999999999999");
2171+
2172+
f.precision = 60;
2173+
assert(printFloat(2.65e-54L, f) ==
2174+
"0.000000000000000000000000000000000000000000000000000002650000");
2175+
2176+
/*
2177+
commented out, because CTFE is currently too slow for 5000 digits with extreme values
2178+
2179+
f.precision = 5000;
2180+
auto result2 = printFloat(1.2119e-4822L, f);
2181+
assert(result2.length == 5002);
2182+
assert(result2[$ - 20 .. $] == "60076763752233836613");
2183+
auto result3 = printFloat(real.min_normal, f);
2184+
assert(result3.length == 5002);
2185+
assert(result3[$ - 20 .. $] == "47124010882722980874");
2186+
auto result4 = printFloat(real.min_normal.nextDown, f);
2187+
assert(result4.length == 5002);
2188+
assert(result4[$ - 20 .. $] == "52925846892214823939");
2189+
*/
2190+
}
21852191
}
21862192
});
21872193
}
@@ -2830,37 +2836,40 @@ if (is(T == float) || is(T == double)
28302836

28312837
assertCTFEable!(
28322838
{
2833-
// log2 is broken for x87-reals on some computers in CTFE
2834-
// the following tests excludes these computers from the tests
2835-
// (https://issues.dlang.org/show_bug.cgi?id=21757)
2836-
enum test = cast(int) log2(3.05e2312L);
2837-
static if (real.mant_dig == 64 && test == 7681)
2839+
static if (real.mant_dig == 64) // 80 bit reals
28382840
{
2839-
auto f = FormatSpec!dchar("");
2840-
f.spec = 'g';
2841-
assert(printFloat(real.infinity, f) == "inf");
2842-
assert(printFloat(10.0L, f) == "10");
2843-
assert(printFloat(2.6080L, f) == "2.608");
2844-
assert(printFloat(3.05e2312L, f) == "3.05e+2312");
2845-
2846-
f.precision = 60;
2847-
assert(printFloat(2.65e-54L, f) ==
2848-
"2.65000000000000000005900998740054701394102894093529654759941e-54");
2849-
2850-
/*
2851-
commented out, because CTFE is currently too slow for 5000 digits with extreme values
2852-
2853-
f.precision = 5000;
2854-
auto result2 = printFloat(1.2119e-4822L, f);
2855-
assert(result2.length == 5007);
2856-
assert(result2[$ - 20 .. $] == "26072948659534e-4822");
2857-
auto result3 = printFloat(real.min_normal, f);
2858-
assert(result3.length == 5007);
2859-
assert(result3[$ - 20 .. $] == "72078141008227e-4932");
2860-
auto result4 = printFloat(real.min_normal.nextDown, f);
2861-
assert(result4.length == 5007);
2862-
assert(result4[$ - 20 .. $] == "48141326333101e-4932");
2863-
*/
2841+
// log2 is broken for x87-reals on some computers in CTFE
2842+
// the following tests excludes these computers from the tests
2843+
// (https://issues.dlang.org/show_bug.cgi?id=21757)
2844+
enum test = cast(int) log2(3.05e2312L);
2845+
static if (test == 7681)
2846+
{
2847+
auto f = FormatSpec!dchar("");
2848+
f.spec = 'g';
2849+
assert(printFloat(real.infinity, f) == "inf");
2850+
assert(printFloat(10.0L, f) == "10");
2851+
assert(printFloat(2.6080L, f) == "2.608");
2852+
assert(printFloat(3.05e2312L, f) == "3.05e+2312");
2853+
2854+
f.precision = 60;
2855+
assert(printFloat(2.65e-54L, f) ==
2856+
"2.65000000000000000005900998740054701394102894093529654759941e-54");
2857+
2858+
/*
2859+
commented out, because CTFE is currently too slow for 5000 digits with extreme values
2860+
2861+
f.precision = 5000;
2862+
auto result2 = printFloat(1.2119e-4822L, f);
2863+
assert(result2.length == 5007);
2864+
assert(result2[$ - 20 .. $] == "26072948659534e-4822");
2865+
auto result3 = printFloat(real.min_normal, f);
2866+
assert(result3.length == 5007);
2867+
assert(result3[$ - 20 .. $] == "72078141008227e-4932");
2868+
auto result4 = printFloat(real.min_normal.nextDown, f);
2869+
assert(result4.length == 5007);
2870+
assert(result4[$ - 20 .. $] == "48141326333101e-4932");
2871+
*/
2872+
}
28642873
}
28652874
});
28662875
}

std/format/internal/write.d

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -902,13 +902,14 @@ if (is(FloatingPointTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))
902902
{
903903
import std.math.exponential : log2;
904904

905-
// log2 is broken for x87-reals on some computers in CTFE
906-
// the following test excludes these computers from the test
907-
// (https://issues.dlang.org/show_bug.cgi?id=21757)
908-
enum test = cast(int) log2(3.05e2312L);
909-
static if (real.mant_dig == 64 && test == 7681) // 80 bit reals
905+
static if (real.mant_dig == 64) // 80 bit reals
910906
{
911-
static assert(format!"%e"(real.max) == "1.189731e+4932");
907+
// log2 is broken for x87-reals on some computers in CTFE
908+
// the following test excludes these computers from the test
909+
// (https://issues.dlang.org/show_bug.cgi?id=21757)
910+
enum test = cast(int) log2(3.05e2312L);
911+
static if (test == 7681)
912+
static assert(format!"%e"(real.max) == "1.189731e+4932");
912913
}
913914
}
914915

std/math/operations.d

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,52 +1950,55 @@ if (isFloatingPoint!T)
19501950

19511951
alias F = floatTraits!real;
19521952

1953-
// log2 is broken for x87-reals on some computers in CTFE
1954-
// the following test excludes these computers from the test
1955-
// (https://issues.dlang.org/show_bug.cgi?id=21757)
1956-
enum test = cast(int) log2(3.05e2312L);
1957-
static if (F.realFormat == RealFormat.ieeeExtended && test == 7681)
1953+
static if (F.realFormat == RealFormat.ieeeExtended)
19581954
{
1959-
enum r1 = 1.0L;
1960-
enum bp1 = extractBitpattern(r1);
1961-
static assert(bp1.mantissa == 0x8000_0000_0000_0000L);
1962-
static assert(bp1.exponent == 0);
1963-
static assert(bp1.negative == false);
1964-
1965-
enum r2 = real.max;
1966-
enum bp2 = extractBitpattern(r2);
1967-
static assert(bp2.mantissa == 0xffff_ffff_ffff_ffffL);
1968-
static assert(bp2.exponent == 16383);
1969-
static assert(bp2.negative == false);
1970-
1971-
enum r3 = -1.5432e-3333L;
1972-
enum bp3 = extractBitpattern(r3);
1973-
static assert(bp3.mantissa == 0xc768_a2c7_a616_cc22L);
1974-
static assert(bp3.exponent == -11072);
1975-
static assert(bp3.negative == true);
1976-
1977-
enum r4 = 0.0L.nextUp;
1978-
enum bp4 = extractBitpattern(r4);
1979-
static assert(bp4.mantissa == 0x0000_0000_0000_0001L);
1980-
static assert(bp4.exponent == -16382);
1981-
static assert(bp4.negative == false);
1982-
1983-
enum r5 = -real.infinity;
1984-
enum bp5 = extractBitpattern(r5);
1985-
static assert(bp5.mantissa == 0);
1986-
static assert(bp5.exponent == 16384);
1987-
static assert(bp5.negative == true);
1988-
1989-
enum r6 = real.nan;
1990-
enum bp6 = extractBitpattern(r6);
1991-
static assert(bp6.mantissa != 0); // we don't guarantee payloads
1992-
static assert(bp6.exponent == 16384);
1993-
static assert(bp6.negative == false);
1994-
1995-
enum r7 = nextDown(0x1p+16383L);
1996-
enum bp7 = extractBitpattern(r7);
1997-
static assert(bp7.mantissa == 0xffff_ffff_ffff_ffffL);
1998-
static assert(bp7.exponent == 16382);
1999-
static assert(bp7.negative == false);
1955+
// log2 is broken for x87-reals on some computers in CTFE
1956+
// the following test excludes these computers from the test
1957+
// (https://issues.dlang.org/show_bug.cgi?id=21757)
1958+
enum test = cast(int) log2(3.05e2312L);
1959+
static if (test == 7681)
1960+
{
1961+
enum r1 = 1.0L;
1962+
enum bp1 = extractBitpattern(r1);
1963+
static assert(bp1.mantissa == 0x8000_0000_0000_0000L);
1964+
static assert(bp1.exponent == 0);
1965+
static assert(bp1.negative == false);
1966+
1967+
enum r2 = real.max;
1968+
enum bp2 = extractBitpattern(r2);
1969+
static assert(bp2.mantissa == 0xffff_ffff_ffff_ffffL);
1970+
static assert(bp2.exponent == 16383);
1971+
static assert(bp2.negative == false);
1972+
1973+
enum r3 = -1.5432e-3333L;
1974+
enum bp3 = extractBitpattern(r3);
1975+
static assert(bp3.mantissa == 0xc768_a2c7_a616_cc22L);
1976+
static assert(bp3.exponent == -11072);
1977+
static assert(bp3.negative == true);
1978+
1979+
enum r4 = 0.0L.nextUp;
1980+
enum bp4 = extractBitpattern(r4);
1981+
static assert(bp4.mantissa == 0x0000_0000_0000_0001L);
1982+
static assert(bp4.exponent == -16382);
1983+
static assert(bp4.negative == false);
1984+
1985+
enum r5 = -real.infinity;
1986+
enum bp5 = extractBitpattern(r5);
1987+
static assert(bp5.mantissa == 0);
1988+
static assert(bp5.exponent == 16384);
1989+
static assert(bp5.negative == true);
1990+
1991+
enum r6 = real.nan;
1992+
enum bp6 = extractBitpattern(r6);
1993+
static assert(bp6.mantissa != 0); // we don't guarantee payloads
1994+
static assert(bp6.exponent == 16384);
1995+
static assert(bp6.negative == false);
1996+
1997+
enum r7 = nextDown(0x1p+16383L);
1998+
enum bp7 = extractBitpattern(r7);
1999+
static assert(bp7.mantissa == 0xffff_ffff_ffff_ffffL);
2000+
static assert(bp7.exponent == 16382);
2001+
static assert(bp7.negative == false);
2002+
}
20002003
}
20012004
}

0 commit comments

Comments
 (0)