newCTFE Status November 2018
Nathan S.
no.public.email at example.com
Sun Dec 9 16:32:49 UTC 2018
On Saturday, 8 December 2018 at 15:56:46 UTC, kinke wrote:
> On Saturday, 8 December 2018 at 07:08:54 UTC, Stefan Koch wrote:
>> On Saturday, 8 December 2018 at 04:06:11 UTC, Joakim wrote:
>>> Btw, do you know some way to get the current compile-time
>>> real's precision in D code?
>>
>> this _may_ work:
>> static immutable ctRealPerc = () { return real.mant_dig; } ();
>
> Nope, these FP type properties represent the target type's.
> There's just no way of knowing the compile-time precision at
> the moment, at least for LDC (DMD is x86 only and currently
> always uses a x87 `real_t`). For LDC, it's the host `real`
> precision, except for MSVC hosts, where it uses x87 (Rainer's
> custom implementation in dmd.root.longdouble).
This infallibly determines the precision used for calculations
involving `real` in CTFE:
----
enum ctfeRealExponentBits =
() {
real f = 2;
foreach (i; 1 .. 2000)
{
real g = f * f;
if (g == f)
return i;
f = g;
}
assert(0, "algorithm failure");
}();
enum ctfeMantissaBits =
() {
real a = 1;
real b = 0.5;
int bits = 0;
while (a + b != a)
{
bits = bits + 1;
b = b / 2;
}
// Result matches what would be reported by mant_dig
// (1 greater than the actual number of mantissa bits
// except for 80-bit extended precision).
return bits + 1;
}();
----
More information about the Digitalmars-d
mailing list