2 * Collects functions for compile-time floating-point calculations.
4 * Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
5 * Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
6 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/root/ctfloat.d, root/_ctfloat.d)
8 * Documentation: https://dlang.org/phobos/dmd_root_ctfloat.html
9 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/root/ctfloat.d
12 module dmd
.root
.ctfloat
;
16 // Type used by the front-end for compile-time reals
17 public import dmd
.root
.longdouble
: real_t
= longdouble
;
19 // Compile-time floating-point helper
20 extern (C
++) struct CTFloat
27 enum yl2x_supported
= false;
29 enum yl2x_supported
= __traits(compiles
, core
.math
.yl2x(1.0L, 2.0L));
30 enum yl2xp1_supported
= yl2x_supported
;
32 pure static real_t
fabs(real_t x
);
33 pure static real_t
ldexp(real_t n
, int exp
);
36 static bool isIdentical(real_t a
, real_t b
);
39 static size_t
hash(real_t a
);
42 static bool isNaN(real_t r
);
45 static bool isSNaN(real_t r
);
47 static bool isInfinity(real_t r
) pure;
50 static real_t
parse(const(char)* literal
, out bool isOutOfRange
);
53 static int sprint(char* str, size_t size
, char fmt
, real_t x
);
55 // Constant real values 0, 1, -1 and 0.5.
56 __gshared real_t zero
;
58 __gshared real_t minusone
;
59 __gshared real_t half
;
62 static void initialize();