1 
2 /* Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved
3  * http://www.digitalmars.com
4  * Distributed under the Boost Software License, Version 1.0.
5  * http://www.boost.org/LICENSE_1_0.txt
6  * https://github.com/dlang/dmd/blob/master/src/dmd/root/ctfloat.h
7  */
8 
9 #pragma once
10 
11 #include "longdouble.h"
12 
13 // Type used by the front-end for compile-time reals
14 typedef longdouble real_t;
15 
16 // Compile-time floating-point helper
17 struct CTFloat
18 {
19     static bool yl2x_supported;
20     static bool yl2xp1_supported;
21 
22     static void yl2x(const real_t *x, const real_t *y, real_t *res);
23     static void yl2xp1(const real_t *x, const real_t *y, real_t *res);
24 
25     static real_t sin(real_t x);
26     static real_t cos(real_t x);
27     static real_t tan(real_t x);
28     static real_t sqrt(real_t x);
29     static real_t fabs(real_t x);
30     static real_t ldexp(real_t n, int exp);
31 
32     static real_t round(real_t x);
33     static real_t floor(real_t x);
34     static real_t ceil(real_t x);
35     static real_t trunc(real_t x);
36     static real_t log(real_t x);
37     static real_t log2(real_t x);
38     static real_t log10(real_t x);
39     static real_t pow(real_t x, real_t y);
40     static real_t exp(real_t x);
41     static real_t expm1(real_t x);
42     static real_t exp2(real_t x);
43 
44     static real_t fmin(real_t x, real_t y);
45     static real_t fmax(real_t x, real_t y);
46     static real_t copysign(real_t x, real_t s);
47 
48     static real_t fma(real_t x, real_t y, real_t z);
49 
50     static bool isIdentical(real_t a, real_t b);
51     static bool isNaN(real_t r);
52     static bool isSNaN(real_t r);
53     static bool isInfinity(real_t r);
54 
55     static real_t parse(const char *literal, bool *isOutOfRange = NULL);
56     static int sprint(char *str, char fmt, real_t x);
57 
58     static size_t hash(real_t a);
59 
60     // Constant real values 0, 1, -1 and 0.5.
61     static real_t zero;
62     static real_t one;
63     static real_t minusone;
64     static real_t half;
65 };
66