xref: /netbsd-src/external/gpl3/gcc/dist/gcc/d/dmd/root/ctfloat.d (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1 /**
2  * Collects functions for compile-time floating-point calculations.
3  *
4  * Copyright:   Copyright (C) 1999-2022 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
10  */
11 
12 module dmd.root.ctfloat;
13 
14 nothrow:
15 
16 // Type used by the front-end for compile-time reals
17 public import dmd.root.longdouble : real_t = longdouble;
18 
19 // Compile-time floating-point helper
20 extern (C++) struct CTFloat
21 {
22   nothrow:
23   @nogc:
24   @safe:
25 
26     version (GNU)
27         enum yl2x_supported = false;
28     else
29         enum yl2x_supported = __traits(compiles, core.math.yl2x(1.0L, 2.0L));
30     enum yl2xp1_supported = yl2x_supported;
31 
32     pure static real_t fabs(real_t x);
33     pure static real_t ldexp(real_t n, int exp);
34 
35     pure @trusted
36     static bool isIdentical(real_t a, real_t b);
37 
38     pure @trusted
39     static size_t hash(real_t a);
40 
41     pure
42     static bool isNaN(real_t r);
43 
44     pure @trusted
45     static bool isSNaN(real_t r);
46 
47     static bool isInfinity(real_t r) pure;
48 
49     @system
50     static real_t parse(const(char)* literal, bool* isOutOfRange = null);
51 
52     @system
53     static int sprint(char* str, char fmt, real_t x);
54 
55     // Constant real values 0, 1, -1 and 0.5.
56     __gshared real_t zero;
57     __gshared real_t one;
58     __gshared real_t minusone;
59     __gshared real_t half;
60 
61     @trusted
62     static void initialize();
63 }
64