FastPolyEval  1.0
Fast Evaluation of Real and Complex Polynomials
ntypes.h
Go to the documentation of this file.
1 //
2 // ntypes.h
3 //
4 // Authors: Nicolae Mihalache & François Vigneron
5 //
6 // This software is released under BSD licence, with an attribution clause (see Licence file).
7 // Please cite the reference below if you use or distribute this software.
8 //
9 // • [1] R. Anton, N. Mihalache & F. Vigneron. Fast evaluation of real and complex polynomials. 2022.
10 // https://hal.archives-ouvertes.fr/hal-03820369
11 //
12 // Copyright 2022 Univ. Paris-Est Créteil & Univ. de Reims Champagne-Ardenne.
13 //
14 
20 #ifndef ntypes_h
21 #define ntypes_h
22 
23 #include <inttypes.h>
24 #include <stdint.h>
25 #include <math.h>
26 
28 typedef uint8_t byte;
29 
31 typedef uint16_t word;
32 
34 typedef uint32_t uint;
35 
37 typedef uint64_t ulong;
38 
40 typedef byte bool;
41 
43 #define true 1
44 
46 #define false 0
47 
49 #define PI (3.14159265358979323846264338327950288L)
50 
51 // comment this line to use the fastest precise machine floating point numbers
52 // for polynomial evaluation (@c fp64 numbers)
53 // leave the line uncommented to use @c fp80 numbers on x86 machines, that occupy
54 // 16 bytes of memory, but only use 10 bytes for storing the numbers
55 // #define MACHINE_EXTRA_PREC
56 
57 // Comment the previous line and uncomment this line to use 32-bit floats for coefficients
58 // #define MACHINE_LOW_PREC
59 
61 #ifdef MACHINE_EXTRA_PREC
62  typedef long double coeff_t;
63  #define flog2 log2l
64  #define fhypot hypotl
65  #define ffloor floorl
66  #define fpow powl
67  #define fexp expl
68  #define fsin sinl
69  #define fcos cosl
70  #define ftan tanl
71  #define mpfr_getf mpfr_get_ld
72  #define precf 64
73  #define PRECF_STR "64"
74  #define TYPEFP_STR "FP80"
75  #define TYPEF_STR "long double"
76  #define INF_M (-HUGE_VALL)
77  #define INF_P HUGE_VALL
78  #define FMT_COEFF "L"
79 #else
80 #ifndef MACHINE_LOW_PREC
81  typedef double coeff_t;
82  #define flog2 log2
83  #define fhypot hypot
84  #define ffloor floor
85  #define fpow pow
86  #define fexp exp
87  #define fsin sin
88  #define fcos cos
89  #define ftan tan
90  #define mpfr_getf mpfr_get_d
91  #define precf 53
92  #define PRECF_STR "53"
93  #define TYPEFP_STR "FP64"
94  #define TYPEF_STR "double"
95  #define INF_M (-HUGE_VAL)
96  #define INF_P HUGE_VAL
97  #define FMT_COEFF "l"
98 #else
99  typedef float coeff_t;
100  #define flog2 log2f
101  #define fhypot hypotf
102  #define ffloor floorf
103  #define fpow powf
104  #define fexp expf
105  #define fsin sinf
106  #define fcos cosf
107  #define ftan tanf
108  #define mpfr_getf mpfr_get_f
109  #define precf 24
110  #define PRECF_STR "24"
111  #define TYPEFP_STR "FP32"
112  #define TYPEF_STR "float"
113  #define INF_M (-HUGE_VALF)
114  #define INF_P HUGE_VALF
115  #define FMT_COEFF ""
116 #endif
117 #endif
118 
119 #define MAX_EXP (sizeof(coeff_t) == 8 ? 960 : 16320)
120 
121 
122 // Comment this line to limit the degree of the polynomials to 2^32-2
123 // leave this line uncommented to use degrees up to 2^64-2
124 #define HUGE_DEGREES
125 
127 #ifdef HUGE_DEGREES
128  typedef ulong deg_t;
129  #define MAX_DEG (UINT64_MAX - 1)
130  #define FMT_DEG PRIu64
131 #else
132  typedef uint deg_t;
133  #define MAX_DEG (UINT32_MAX - 1)
134  #define FMT_DEG PRIu32
135 #endif
136 
137 
138 // Comment this line to use the fastest precise machine floating point numbers
139 // for polynomial pre-condtionning; largely enough in 99+% usage cases
140 // leave the line uncommented to use @c fp80 numbers on x86 machines, that occupy
141 // 16 bytes of memory, but only use 10 bytes for storing the numbers
142 //#define INTERNAL_EXTRA_PREC
143 
145 #ifdef INTERNAL_EXTRA_PREC
146  typedef long double real_t;
147  #define plog2 log2l
148  #define pexp2 exp2l
149  #define phypot hypotl
150  #define pfloor floorl
151  #define pceil ceill
152  #define mpfr_getp mpfr_get_ld
153  #define PEPS 1E-3000L
154  #define PDEL 1E-15L
155  #define pexp expl
156  #define pcos cosl
157  #define psin sinl
158  #define ptan tanl
159  #define pldexp ldexpl
160  #define pfrexp frexpl
161  #define FMT_REAL "L"
162 #else
163  typedef double real_t;
164  #define plog2 log2
165  #define pexp2 exp2
166  #define phypot hypot
167  #define pfloor floor
168  #define pceil ceil
169  #define mpfr_getp mpfr_get_d
170  #define PEPS 1E-200
171  #define PDEL 1E-12
172  #define pexp exp
173  #define pcos cos
174  #define psin sin
175  #define ptan tan
176  #define pldexp ldexp
177  #define pfrexp frexp
178  #define FMT_REAL "l"
179 #endif
180 
181 
182 // Comment this line to limit the precision of mpfr numbers to to 4 * 10^9
183 // leave this line uncommented to use up to 16 * 10^18 bits for each number
184 #define HUGE_PREC
185 
187 #ifdef HUGE_PREC
188  typedef ulong prec_t;
189  #define MAX_PREC (16000000000000000000UL)
190 #else
191  typedef uint prec_t;
192  #define MAX_PREC (4000000000UL)
193 #endif
194 
195 // Comment this line to limit the exponents of mpfr numbers to to +/- 2 * 10^9
196 // leave this line uncommented to use exponents in the range +/- 4 * 10^18
197 #define HUGE_MP_EXP
198 
200 #ifdef HUGE_MP_EXP
201  #define MAX_MP_EXP (4000000000000000000L)
202 #else
203  #define MAX_MP_EXP (2000000000L)
204 #endif
205 
206 #define NEWTON_CONV_BITS 5
207 #define NEWTON_ESCAPE_BITS 4
208 
210 bool ntypes_check(void);
211 
219 
230 
231 #endif /* ntypes_h */
double real_t
The machine number type to use for polynomial analysis and preconditionning.
Definition: ntypes.h:163
double coeff_t
The machine number type to use for polynomial coefficients and evaluation.
Definition: ntypes.h:81
uint32_t uint
uint is uint32
Definition: ntypes.h:34
real_t bits_sum(real_t b1, real_t b2)
Computes log_2(2^b1+2^b2), even if b1 or b2 are outside the exponent range of real_t.
ulong deg_t
The integer number type to use for polynomial degrees and indexes.
Definition: ntypes.h:128
ulong prec_t
The integer number type to use for polynomial degrees and indexes.
Definition: ntypes.h:188
uint16_t word
word is uint16
Definition: ntypes.h:31
uint64_t ulong
ulong is uint64
Definition: ntypes.h:37
uint8_t byte
byte is uint8
Definition: ntypes.h:28
real_t nt_err(real_t vb, real_t evb, real_t db, real_t edb)
Computes log_2(ntErr), where ntErr is an upper bound for the error of the Newton term.
byte bool
Logic type bool can take values true or false.
Definition: ntypes.h:40
bool ntypes_check(void)
Use this function to check the compatibility of the machine with the settings above.