aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/conv.d
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2020-11-26 11:15:32 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2020-11-27 21:27:13 +0100
commit6ac67dddc31e6ab4f954e27e1f86e005537efc12 (patch)
treec666cde37bcbe432eded6aa61a54abf9b2367e15 /libphobos/src/std/conv.d
parent9285e0f694969dc2d1d9257378ddf6c8ef42de3c (diff)
downloadgcc-6ac67dddc31e6ab4f954e27e1f86e005537efc12.zip
gcc-6ac67dddc31e6ab4f954e27e1f86e005537efc12.tar.gz
gcc-6ac67dddc31e6ab4f954e27e1f86e005537efc12.tar.bz2
libphobos: Merge upstream phobos 38873fe6e.
Adds support for FreeBSD/x86 53-bit precision reals, and removes all support code and tests for the extern(Pascal) calling convention. Reviewed-on: https://github.com/dlang/phobos/pull/7704 https://github.com/dlang/phobos/pull/7705 libphobos/ChangeLog: * src/MERGE: Merge upstream phobos 38873fe6e.
Diffstat (limited to 'libphobos/src/std/conv.d')
-rw-r--r--libphobos/src/std/conv.d26
1 files changed, 20 insertions, 6 deletions
diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d
index eaee62f..743d203 100644
--- a/libphobos/src/std/conv.d
+++ b/libphobos/src/std/conv.d
@@ -1629,6 +1629,8 @@ private void testIntegralToFloating(Integral, Floating)()
private void testFloatingToIntegral(Floating, Integral)()
{
+ import std.math : floatTraits, RealFormat;
+
bool convFails(Source, Target, E)(Source src)
{
try
@@ -1660,18 +1662,23 @@ private void testFloatingToIntegral(Floating, Integral)()
{
a = -a; // -Integral.min not representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
- || Floating.sizeof <= Integral.sizeof);
+ || Floating.sizeof <= Integral.sizeof
+ || floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
}
a = 0.0 + Integral.min;
assert(to!Integral(a) == Integral.min);
--a; // no more representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
- || Floating.sizeof <= Integral.sizeof);
+ || Floating.sizeof <= Integral.sizeof
+ || floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
a = 0.0 + Integral.max;
- assert(to!Integral(a) == Integral.max || Floating.sizeof <= Integral.sizeof);
+ assert(to!Integral(a) == Integral.max
+ || Floating.sizeof <= Integral.sizeof
+ || floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
++a; // no more representable as an Integral
assert(convFails!(Floating, Integral, ConvOverflowException)(a)
- || Floating.sizeof <= Integral.sizeof);
+ || Floating.sizeof <= Integral.sizeof
+ || floatTraits!Floating.realFormat == RealFormat.ieeeExtended53);
// convert a value with a fractional part
a = 3.14;
assert(to!Integral(a) == 3);
@@ -3016,7 +3023,9 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum
@system unittest
{
// @system because strtod is not @safe.
- static if (real.mant_dig == 53)
+ import std.math : floatTraits, RealFormat;
+
+ static if (floatTraits!real.realFormat == RealFormat.ieeeDouble)
{
import core.stdc.stdlib, std.exception, std.math;
@@ -3099,7 +3108,8 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum
{
ushort[8] value;
}
- else static if (floatTraits!real.realFormat == RealFormat.ieeeExtended)
+ else static if (floatTraits!real.realFormat == RealFormat.ieeeExtended ||
+ floatTraits!real.realFormat == RealFormat.ieeeExtended53)
{
ushort[5] value;
}
@@ -3122,6 +3132,8 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum
enum s = "0x1.FFFFFFFFFFFFFFFEp-16382";
else static if (floatTraits!real.realFormat == RealFormat.ieeeExtended)
enum s = "0x1.FFFFFFFFFFFFFFFEp-16382";
+ else static if (floatTraits!real.realFormat == RealFormat.ieeeExtended53)
+ enum s = "0x1.FFFFFFFFFFFFFFFEp-16382";
else static if (floatTraits!real.realFormat == RealFormat.ieeeDouble)
enum s = "0x1.FFFFFFFFFFFFFFFEp-1000";
else
@@ -3141,6 +3153,8 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum
else
ld1 = strtold(s.ptr, null);
}
+ else static if (floatTraits!real.realFormat == RealFormat.ieeeExtended53)
+ ld1 = 0x1.FFFFFFFFFFFFFFFEp-16382L; // strtold rounds to 53 bits.
else
ld1 = strtold(s.ptr, null);