newCTFE Status November 2018
Joakim
dlang at joakim.fea.st
Sun Dec 9 16:59:53 UTC 2018
On Sunday, 9 December 2018 at 16:32:49 UTC, Nathan S. wrote:
> On Saturday, 8 December 2018 at 15:56:46 UTC, kinke wrote:
>> [...]
>
> 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;
> }();
> ----
Heh, yes, checking the precision manually with a compile-time
while loop works: he meant there's no "FP type properties" that
will easily give it to you.
More information about the Digitalmars-d
mailing list