Bug 1888033 - [Menu Redesign] Add a secret setting and feature flag for the menu...
[gecko.git] / modules / fdlibm / src / math_private.h
blobb588a5905f40597f78f6a069ed6571f8cb74b57c
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 * $FreeBSD$
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
20 #include <cfloat>
21 #include <stdint.h>
22 #include <sys/types.h>
24 #include "mozilla/EndianUtils.h"
26 #include "fdlibm.h"
29 * Emulate FreeBSD internal double types.
30 * Adapted from https://github.com/freebsd/freebsd-src/search?q=__double_t
33 typedef double __double_t;
34 typedef __double_t double_t;
35 typedef float __float_t;
38 * The original fdlibm code used statements like:
39 * n0 = ((*(int*)&one)>>29)^1; * index of high word *
40 * ix0 = *(n0+(int*)&x); * high word of x *
41 * ix1 = *((1-n0)+(int*)&x); * low word of x *
42 * to dig two 32 bit words out of the 64 bit IEEE floating point
43 * value. That is non-ANSI, and, moreover, the gcc instruction
44 * scheduler gets it wrong. We instead use the following macros.
45 * Unlike the original code, we determine the endianness at compile
46 * time, not at run time; I don't see much benefit to selecting
47 * endianness at run time.
50 #ifndef u_int32_t
51 #define u_int32_t uint32_t
52 #endif
53 #ifndef u_int64_t
54 #define u_int64_t uint64_t
55 #endif
57 /* A union which permits us to convert between a long double and
58 four 32 bit ints. */
60 #if MOZ_BIG_ENDIAN()
62 typedef union
64 long double value;
65 struct {
66 u_int32_t mswhi;
67 u_int32_t mswlo;
68 u_int32_t lswhi;
69 u_int32_t lswlo;
70 } parts32;
71 struct {
72 u_int64_t msw;
73 u_int64_t lsw;
74 } parts64;
75 } ieee_quad_shape_type;
77 #endif
79 #if MOZ_LITTLE_ENDIAN()
81 typedef union
83 long double value;
84 struct {
85 u_int32_t lswlo;
86 u_int32_t lswhi;
87 u_int32_t mswlo;
88 u_int32_t mswhi;
89 } parts32;
90 struct {
91 u_int64_t lsw;
92 u_int64_t msw;
93 } parts64;
94 } ieee_quad_shape_type;
96 #endif
98 #if MOZ_BIG_ENDIAN()
100 typedef union
102 double value;
103 struct
105 u_int32_t msw;
106 u_int32_t lsw;
107 } parts;
108 struct
110 u_int64_t w;
111 } xparts;
112 } ieee_double_shape_type;
114 #endif
116 #if MOZ_LITTLE_ENDIAN()
118 typedef union
120 double value;
121 struct
123 u_int32_t lsw;
124 u_int32_t msw;
125 } parts;
126 struct
128 u_int64_t w;
129 } xparts;
130 } ieee_double_shape_type;
132 #endif
134 /* Get two 32 bit ints from a double. */
136 #define EXTRACT_WORDS(ix0,ix1,d) \
137 do { \
138 ieee_double_shape_type ew_u; \
139 ew_u.value = (d); \
140 (ix0) = ew_u.parts.msw; \
141 (ix1) = ew_u.parts.lsw; \
142 } while (0)
144 /* Get a 64-bit int from a double. */
145 #define EXTRACT_WORD64(ix,d) \
146 do { \
147 ieee_double_shape_type ew_u; \
148 ew_u.value = (d); \
149 (ix) = ew_u.xparts.w; \
150 } while (0)
152 /* Get the more significant 32 bit int from a double. */
154 #define GET_HIGH_WORD(i,d) \
155 do { \
156 ieee_double_shape_type gh_u; \
157 gh_u.value = (d); \
158 (i) = gh_u.parts.msw; \
159 } while (0)
161 /* Get the less significant 32 bit int from a double. */
163 #define GET_LOW_WORD(i,d) \
164 do { \
165 ieee_double_shape_type gl_u; \
166 gl_u.value = (d); \
167 (i) = gl_u.parts.lsw; \
168 } while (0)
170 /* Set a double from two 32 bit ints. */
172 #define INSERT_WORDS(d,ix0,ix1) \
173 do { \
174 ieee_double_shape_type iw_u; \
175 iw_u.parts.msw = (ix0); \
176 iw_u.parts.lsw = (ix1); \
177 (d) = iw_u.value; \
178 } while (0)
180 /* Set a double from a 64-bit int. */
181 #define INSERT_WORD64(d,ix) \
182 do { \
183 ieee_double_shape_type iw_u; \
184 iw_u.xparts.w = (ix); \
185 (d) = iw_u.value; \
186 } while (0)
188 /* Set the more significant 32 bits of a double from an int. */
190 #define SET_HIGH_WORD(d,v) \
191 do { \
192 ieee_double_shape_type sh_u; \
193 sh_u.value = (d); \
194 sh_u.parts.msw = (v); \
195 (d) = sh_u.value; \
196 } while (0)
198 /* Set the less significant 32 bits of a double from an int. */
200 #define SET_LOW_WORD(d,v) \
201 do { \
202 ieee_double_shape_type sl_u; \
203 sl_u.value = (d); \
204 sl_u.parts.lsw = (v); \
205 (d) = sl_u.value; \
206 } while (0)
209 * A union which permits us to convert between a float and a 32 bit
210 * int.
213 typedef union
215 float value;
216 /* FIXME: Assumes 32 bit int. */
217 unsigned int word;
218 } ieee_float_shape_type;
220 /* Get a 32 bit int from a float. */
222 #define GET_FLOAT_WORD(i,d) \
223 do { \
224 ieee_float_shape_type gf_u; \
225 gf_u.value = (d); \
226 (i) = gf_u.word; \
227 } while (0)
229 /* Set a float from a 32 bit int. */
231 #define SET_FLOAT_WORD(d,i) \
232 do { \
233 ieee_float_shape_type sf_u; \
234 sf_u.word = (i); \
235 (d) = sf_u.value; \
236 } while (0)
239 * Get expsign and mantissa as 16 bit and 64 bit ints from an 80 bit long
240 * double.
243 #define EXTRACT_LDBL80_WORDS(ix0,ix1,d) \
244 do { \
245 union IEEEl2bits ew_u; \
246 ew_u.e = (d); \
247 (ix0) = ew_u.xbits.expsign; \
248 (ix1) = ew_u.xbits.man; \
249 } while (0)
252 * Get expsign and mantissa as one 16 bit and two 64 bit ints from a 128 bit
253 * long double.
256 #define EXTRACT_LDBL128_WORDS(ix0,ix1,ix2,d) \
257 do { \
258 union IEEEl2bits ew_u; \
259 ew_u.e = (d); \
260 (ix0) = ew_u.xbits.expsign; \
261 (ix1) = ew_u.xbits.manh; \
262 (ix2) = ew_u.xbits.manl; \
263 } while (0)
265 /* Get expsign as a 16 bit int from a long double. */
267 #define GET_LDBL_EXPSIGN(i,d) \
268 do { \
269 union IEEEl2bits ge_u; \
270 ge_u.e = (d); \
271 (i) = ge_u.xbits.expsign; \
272 } while (0)
275 * Set an 80 bit long double from a 16 bit int expsign and a 64 bit int
276 * mantissa.
279 #define INSERT_LDBL80_WORDS(d,ix0,ix1) \
280 do { \
281 union IEEEl2bits iw_u; \
282 iw_u.xbits.expsign = (ix0); \
283 iw_u.xbits.man = (ix1); \
284 (d) = iw_u.e; \
285 } while (0)
288 * Set a 128 bit long double from a 16 bit int expsign and two 64 bit ints
289 * comprising the mantissa.
292 #define INSERT_LDBL128_WORDS(d,ix0,ix1,ix2) \
293 do { \
294 union IEEEl2bits iw_u; \
295 iw_u.xbits.expsign = (ix0); \
296 iw_u.xbits.manh = (ix1); \
297 iw_u.xbits.manl = (ix2); \
298 (d) = iw_u.e; \
299 } while (0)
301 /* Set expsign of a long double from a 16 bit int. */
303 #define SET_LDBL_EXPSIGN(d,v) \
304 do { \
305 union IEEEl2bits se_u; \
306 se_u.e = (d); \
307 se_u.xbits.expsign = (v); \
308 (d) = se_u.e; \
309 } while (0)
311 #ifdef __i386__
312 /* Long double constants are broken on i386. */
313 #define LD80C(m, ex, v) { \
314 .xbits.man = __CONCAT(m, ULL), \
315 .xbits.expsign = (0x3fff + (ex)) | ((v) < 0 ? 0x8000 : 0), \
317 #else
318 /* The above works on non-i386 too, but we use this to check v. */
319 #define LD80C(m, ex, v) { .e = (v), }
320 #endif
322 #ifdef FLT_EVAL_METHOD
324 * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
326 #if !defined(_MSC_VER) && (FLT_EVAL_METHOD == 0 || __GNUC__ == 0)
327 #define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
328 #else
329 #define STRICT_ASSIGN(type, lval, rval) do { \
330 volatile type __lval; \
332 if (sizeof(type) >= sizeof(long double)) \
333 (lval) = (rval); \
334 else { \
335 __lval = (rval); \
336 (lval) = __lval; \
338 } while (0)
339 #endif
340 #else
341 #define STRICT_ASSIGN(type, lval, rval) do { \
342 volatile type __lval; \
344 if (sizeof(type) >= sizeof(long double)) \
345 (lval) = (rval); \
346 else { \
347 __lval = (rval); \
348 (lval) = __lval; \
350 } while (0)
351 #endif /* FLT_EVAL_METHOD */
353 /* Support switching the mode to FP_PE if necessary. */
354 #if defined(__i386__) && !defined(NO_FPSETPREC)
355 #define ENTERI() ENTERIT(long double)
356 #define ENTERIT(returntype) \
357 returntype __retval; \
358 fp_prec_t __oprec; \
360 if ((__oprec = fpgetprec()) != FP_PE) \
361 fpsetprec(FP_PE)
362 #define RETURNI(x) do { \
363 __retval = (x); \
364 if (__oprec != FP_PE) \
365 fpsetprec(__oprec); \
366 RETURNF(__retval); \
367 } while (0)
368 #define ENTERV() \
369 fp_prec_t __oprec; \
371 if ((__oprec = fpgetprec()) != FP_PE) \
372 fpsetprec(FP_PE)
373 #define RETURNV() do { \
374 if (__oprec != FP_PE) \
375 fpsetprec(__oprec); \
376 return; \
377 } while (0)
378 #else
379 #define ENTERI()
380 #define ENTERIT(x)
381 #define RETURNI(x) RETURNF(x)
382 #define ENTERV()
383 #define RETURNV() return
384 #endif
386 /* Default return statement if hack*_t() is not used. */
387 #define RETURNF(v) return (v)
390 * 2sum gives the same result as 2sumF without requiring |a| >= |b| or
391 * a == 0, but is slower.
393 #define _2sum(a, b) do { \
394 __typeof(a) __s, __w; \
396 __w = (a) + (b); \
397 __s = __w - (a); \
398 (b) = ((a) - (__w - __s)) + ((b) - __s); \
399 (a) = __w; \
400 } while (0)
403 * 2sumF algorithm.
405 * "Normalize" the terms in the infinite-precision expression a + b for
406 * the sum of 2 floating point values so that b is as small as possible
407 * relative to 'a'. (The resulting 'a' is the value of the expression in
408 * the same precision as 'a' and the resulting b is the rounding error.)
409 * |a| must be >= |b| or 0, b's type must be no larger than 'a's type, and
410 * exponent overflow or underflow must not occur. This uses a Theorem of
411 * Dekker (1971). See Knuth (1981) 4.2.2 Theorem C. The name "TwoSum"
412 * is apparently due to Skewchuk (1997).
414 * For this to always work, assignment of a + b to 'a' must not retain any
415 * extra precision in a + b. This is required by C standards but broken
416 * in many compilers. The brokenness cannot be worked around using
417 * STRICT_ASSIGN() like we do elsewhere, since the efficiency of this
418 * algorithm would be destroyed by non-null strict assignments. (The
419 * compilers are correct to be broken -- the efficiency of all floating
420 * point code calculations would be destroyed similarly if they forced the
421 * conversions.)
423 * Fortunately, a case that works well can usually be arranged by building
424 * any extra precision into the type of 'a' -- 'a' should have type float_t,
425 * double_t or long double. b's type should be no larger than 'a's type.
426 * Callers should use these types with scopes as large as possible, to
427 * reduce their own extra-precision and efficiciency problems. In
428 * particular, they shouldn't convert back and forth just to call here.
430 #ifdef DEBUG
431 #define _2sumF(a, b) do { \
432 __typeof(a) __w; \
433 volatile __typeof(a) __ia, __ib, __r, __vw; \
435 __ia = (a); \
436 __ib = (b); \
437 assert(__ia == 0 || fabsl(__ia) >= fabsl(__ib)); \
439 __w = (a) + (b); \
440 (b) = ((a) - __w) + (b); \
441 (a) = __w; \
443 /* The next 2 assertions are weak if (a) is already long double. */ \
444 assert((long double)__ia + __ib == (long double)(a) + (b)); \
445 __vw = __ia + __ib; \
446 __r = __ia - __vw; \
447 __r += __ib; \
448 assert(__vw == (a) && __r == (b)); \
449 } while (0)
450 #else /* !DEBUG */
451 #define _2sumF(a, b) do { \
452 __typeof(a) __w; \
454 __w = (a) + (b); \
455 (b) = ((a) - __w) + (b); \
456 (a) = __w; \
457 } while (0)
458 #endif /* DEBUG */
461 * Set x += c, where x is represented in extra precision as a + b.
462 * x must be sufficiently normalized and sufficiently larger than c,
463 * and the result is then sufficiently normalized.
465 * The details of ordering are that |a| must be >= |c| (so that (a, c)
466 * can be normalized without extra work to swap 'a' with c). The details of
467 * the normalization are that b must be small relative to the normalized 'a'.
468 * Normalization of (a, c) makes the normalized c tiny relative to the
469 * normalized a, so b remains small relative to 'a' in the result. However,
470 * b need not ever be tiny relative to 'a'. For example, b might be about
471 * 2**20 times smaller than 'a' to give about 20 extra bits of precision.
472 * That is usually enough, and adding c (which by normalization is about
473 * 2**53 times smaller than a) cannot change b significantly. However,
474 * cancellation of 'a' with c in normalization of (a, c) may reduce 'a'
475 * significantly relative to b. The caller must ensure that significant
476 * cancellation doesn't occur, either by having c of the same sign as 'a',
477 * or by having |c| a few percent smaller than |a|. Pre-normalization of
478 * (a, b) may help.
480 * This is a variant of an algorithm of Kahan (see Knuth (1981) 4.2.2
481 * exercise 19). We gain considerable efficiency by requiring the terms to
482 * be sufficiently normalized and sufficiently increasing.
484 #define _3sumF(a, b, c) do { \
485 __typeof(a) __tmp; \
487 __tmp = (c); \
488 _2sumF(__tmp, (a)); \
489 (b) += (a); \
490 (a) = __tmp; \
491 } while (0)
494 * Common routine to process the arguments to nan(), nanf(), and nanl().
496 void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
499 * Mix 0, 1 or 2 NaNs. First add 0 to each arg. This normally just turns
500 * signaling NaNs into quiet NaNs by setting a quiet bit. We do this
501 * because we want to never return a signaling NaN, and also because we
502 * don't want the quiet bit to affect the result. Then mix the converted
503 * args using the specified operation.
505 * When one arg is NaN, the result is typically that arg quieted. When both
506 * args are NaNs, the result is typically the quietening of the arg whose
507 * mantissa is largest after quietening. When neither arg is NaN, the
508 * result may be NaN because it is indeterminate, or finite for subsequent
509 * construction of a NaN as the indeterminate 0.0L/0.0L.
511 * Technical complications: the result in bits after rounding to the final
512 * precision might depend on the runtime precision and/or on compiler
513 * optimizations, especially when different register sets are used for
514 * different precisions. Try to make the result not depend on at least the
515 * runtime precision by always doing the main mixing step in long double
516 * precision. Try to reduce dependencies on optimizations by adding the
517 * the 0's in different precisions (unless everything is in long double
518 * precision).
520 #define nan_mix(x, y) (nan_mix_op((x), (y), +))
521 #define nan_mix_op(x, y, op) (((x) + 0.0L) op ((y) + 0))
523 #ifdef _COMPLEX_H
526 * C99 specifies that complex numbers have the same representation as
527 * an array of two elements, where the first element is the real part
528 * and the second element is the imaginary part.
530 typedef union {
531 float complex f;
532 float a[2];
533 } float_complex;
534 typedef union {
535 double complex f;
536 double a[2];
537 } double_complex;
538 typedef union {
539 long double complex f;
540 long double a[2];
541 } long_double_complex;
542 #define REALPART(z) ((z).a[0])
543 #define IMAGPART(z) ((z).a[1])
546 * Inline functions that can be used to construct complex values.
548 * The C99 standard intends x+I*y to be used for this, but x+I*y is
549 * currently unusable in general since gcc introduces many overflow,
550 * underflow, sign and efficiency bugs by rewriting I*y as
551 * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
552 * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
553 * to -0.0+I*0.0.
555 * The C11 standard introduced the macros CMPLX(), CMPLXF() and CMPLXL()
556 * to construct complex values. Compilers that conform to the C99
557 * standard require the following functions to avoid the above issues.
560 #ifndef CMPLXF
561 static __inline float complex
562 CMPLXF(float x, float y)
564 float_complex z;
566 REALPART(z) = x;
567 IMAGPART(z) = y;
568 return (z.f);
570 #endif
572 #ifndef CMPLX
573 static __inline double complex
574 CMPLX(double x, double y)
576 double_complex z;
578 REALPART(z) = x;
579 IMAGPART(z) = y;
580 return (z.f);
582 #endif
584 #ifndef CMPLXL
585 static __inline long double complex
586 CMPLXL(long double x, long double y)
588 long_double_complex z;
590 REALPART(z) = x;
591 IMAGPART(z) = y;
592 return (z.f);
594 #endif
596 #endif /* _COMPLEX_H */
599 * The rnint() family rounds to the nearest integer for a restricted range
600 * range of args (up to about 2**MANT_DIG). We assume that the current
601 * rounding mode is FE_TONEAREST so that this can be done efficiently.
602 * Extra precision causes more problems in practice, and we only centralize
603 * this here to reduce those problems, and have not solved the efficiency
604 * problems. The exp2() family uses a more delicate version of this that
605 * requires extracting bits from the intermediate value, so it is not
606 * centralized here and should copy any solution of the efficiency problems.
609 static inline double
610 rnint(__double_t x)
613 * This casts to double to kill any extra precision. This depends
614 * on the cast being applied to a double_t to avoid compiler bugs
615 * (this is a cleaner version of STRICT_ASSIGN()). This is
616 * inefficient if there actually is extra precision, but is hard
617 * to improve on. We use double_t in the API to minimise conversions
618 * for just calling here. Note that we cannot easily change the
619 * magic number to the one that works directly with double_t, since
620 * the rounding precision is variable at runtime on x86 so the
621 * magic number would need to be variable. Assuming that the
622 * rounding precision is always the default is too fragile. This
623 * and many other complications will move when the default is
624 * changed to FP_PE.
626 return ((double)(x + 0x1.8p52) - 0x1.8p52);
630 * irint() and i64rint() give the same result as casting to their integer
631 * return type provided their arg is a floating point integer. They can
632 * sometimes be more efficient because no rounding is required.
634 #if defined(amd64) || defined(__i386__)
635 #define irint(x) \
636 (sizeof(x) == sizeof(float) && \
637 sizeof(__float_t) == sizeof(long double) ? irintf(x) : \
638 sizeof(x) == sizeof(double) && \
639 sizeof(__double_t) == sizeof(long double) ? irintd(x) : \
640 sizeof(x) == sizeof(long double) ? irintl(x) : (int)(x))
641 #else
642 #define irint(x) ((int)(x))
643 #endif
645 #define i64rint(x) ((int64_t)(x)) /* only needed for ld128 so not opt. */
647 #if defined(__i386__)
648 static __inline int
649 irintf(float x)
651 int n;
653 __asm("fistl %0" : "=m" (n) : "t" (x));
654 return (n);
657 static __inline int
658 irintd(double x)
660 int n;
662 __asm("fistl %0" : "=m" (n) : "t" (x));
663 return (n);
665 #endif
667 #if defined(__amd64__) || defined(__i386__)
668 static __inline int
669 irintl(long double x)
671 int n;
673 __asm("fistl %0" : "=m" (n) : "t" (x));
674 return (n);
676 #endif
678 #ifdef DEBUG
679 #if defined(__amd64__) || defined(__i386__)
680 #define breakpoint() asm("int $3")
681 #else
682 #include <signal.h>
684 #define breakpoint() raise(SIGTRAP)
685 #endif
686 #endif
688 /* Write a pari script to test things externally. */
689 #ifdef DOPRINT
690 #include <stdio.h>
692 #ifndef DOPRINT_SWIZZLE
693 #define DOPRINT_SWIZZLE 0
694 #endif
696 #ifdef DOPRINT_LD80
698 #define DOPRINT_START(xp) do { \
699 uint64_t __lx; \
700 uint16_t __hx; \
702 /* Hack to give more-problematic args. */ \
703 EXTRACT_LDBL80_WORDS(__hx, __lx, *xp); \
704 __lx ^= DOPRINT_SWIZZLE; \
705 INSERT_LDBL80_WORDS(*xp, __hx, __lx); \
706 printf("x = %.21Lg; ", (long double)*xp); \
707 } while (0)
708 #define DOPRINT_END1(v) \
709 printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v))
710 #define DOPRINT_END2(hi, lo) \
711 printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \
712 (long double)(hi), (long double)(lo))
714 #elif defined(DOPRINT_D64)
716 #define DOPRINT_START(xp) do { \
717 uint32_t __hx, __lx; \
719 EXTRACT_WORDS(__hx, __lx, *xp); \
720 __lx ^= DOPRINT_SWIZZLE; \
721 INSERT_WORDS(*xp, __hx, __lx); \
722 printf("x = %.21Lg; ", (long double)*xp); \
723 } while (0)
724 #define DOPRINT_END1(v) \
725 printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v))
726 #define DOPRINT_END2(hi, lo) \
727 printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \
728 (long double)(hi), (long double)(lo))
730 #elif defined(DOPRINT_F32)
732 #define DOPRINT_START(xp) do { \
733 uint32_t __hx; \
735 GET_FLOAT_WORD(__hx, *xp); \
736 __hx ^= DOPRINT_SWIZZLE; \
737 SET_FLOAT_WORD(*xp, __hx); \
738 printf("x = %.21Lg; ", (long double)*xp); \
739 } while (0)
740 #define DOPRINT_END1(v) \
741 printf("y = %.21Lg; z = 0; show(x, y, z);\n", (long double)(v))
742 #define DOPRINT_END2(hi, lo) \
743 printf("y = %.21Lg; z = %.21Lg; show(x, y, z);\n", \
744 (long double)(hi), (long double)(lo))
746 #else /* !DOPRINT_LD80 && !DOPRINT_D64 (LD128 only) */
748 #ifndef DOPRINT_SWIZZLE_HIGH
749 #define DOPRINT_SWIZZLE_HIGH 0
750 #endif
752 #define DOPRINT_START(xp) do { \
753 uint64_t __lx, __llx; \
754 uint16_t __hx; \
756 EXTRACT_LDBL128_WORDS(__hx, __lx, __llx, *xp); \
757 __llx ^= DOPRINT_SWIZZLE; \
758 __lx ^= DOPRINT_SWIZZLE_HIGH; \
759 INSERT_LDBL128_WORDS(*xp, __hx, __lx, __llx); \
760 printf("x = %.36Lg; ", (long double)*xp); \
761 } while (0)
762 #define DOPRINT_END1(v) \
763 printf("y = %.36Lg; z = 0; show(x, y, z);\n", (long double)(v))
764 #define DOPRINT_END2(hi, lo) \
765 printf("y = %.36Lg; z = %.36Lg; show(x, y, z);\n", \
766 (long double)(hi), (long double)(lo))
768 #endif /* DOPRINT_LD80 */
770 #else /* !DOPRINT */
771 #define DOPRINT_START(xp)
772 #define DOPRINT_END1(v)
773 #define DOPRINT_END2(hi, lo)
774 #endif /* DOPRINT */
776 #define RETURNP(x) do { \
777 DOPRINT_END1(x); \
778 RETURNF(x); \
779 } while (0)
780 #define RETURNPI(x) do { \
781 DOPRINT_END1(x); \
782 RETURNI(x); \
783 } while (0)
784 #define RETURN2P(x, y) do { \
785 DOPRINT_END2((x), (y)); \
786 RETURNF((x) + (y)); \
787 } while (0)
788 #define RETURN2PI(x, y) do { \
789 DOPRINT_END2((x), (y)); \
790 RETURNI((x) + (y)); \
791 } while (0)
792 #ifdef STRUCT_RETURN
793 #define RETURNSP(rp) do { \
794 if (!(rp)->lo_set) \
795 RETURNP((rp)->hi); \
796 RETURN2P((rp)->hi, (rp)->lo); \
797 } while (0)
798 #define RETURNSPI(rp) do { \
799 if (!(rp)->lo_set) \
800 RETURNPI((rp)->hi); \
801 RETURN2PI((rp)->hi, (rp)->lo); \
802 } while (0)
803 #endif
804 #define SUM2P(x, y) ({ \
805 const __typeof (x) __x = (x); \
806 const __typeof (y) __y = (y); \
808 DOPRINT_END2(__x, __y); \
809 __x + __y; \
813 * ieee style elementary functions
815 * We rename functions here to improve other sources' diffability
816 * against fdlibm.
818 #define __ieee754_sqrt sqrt
819 #define __ieee754_acos acos
820 #define __ieee754_acosh acosh
821 #define __ieee754_log log
822 #define __ieee754_log2 log2
823 #define __ieee754_atanh atanh
824 #define __ieee754_asin asin
825 #define __ieee754_atan2 atan2
826 #define __ieee754_exp exp
827 #define __ieee754_cosh cosh
828 #define __ieee754_fmod fmod
829 #define __ieee754_pow pow
830 #define __ieee754_lgamma lgamma
831 #define __ieee754_gamma gamma
832 #define __ieee754_lgamma_r lgamma_r
833 #define __ieee754_gamma_r gamma_r
834 #define __ieee754_log10 log10
835 #define __ieee754_sinh sinh
836 #define __ieee754_hypot hypot
837 #define __ieee754_j0 j0
838 #define __ieee754_j1 j1
839 #define __ieee754_y0 y0
840 #define __ieee754_y1 y1
841 #define __ieee754_jn jn
842 #define __ieee754_yn yn
843 #define __ieee754_remainder remainder
844 #define __ieee754_scalb scalb
845 #define __ieee754_sqrtf sqrtf
846 #define __ieee754_acosf acosf
847 #define __ieee754_acoshf acoshf
848 #define __ieee754_logf logf
849 #define __ieee754_atanhf atanhf
850 #define __ieee754_asinf asinf
851 #define __ieee754_atan2f atan2f
852 #define __ieee754_expf expf
853 #define __ieee754_coshf coshf
854 #define __ieee754_fmodf fmodf
855 #define __ieee754_powf powf
856 #define __ieee754_lgammaf lgammaf
857 #define __ieee754_gammaf gammaf
858 #define __ieee754_lgammaf_r lgammaf_r
859 #define __ieee754_gammaf_r gammaf_r
860 #define __ieee754_log10f log10f
861 #define __ieee754_log2f log2f
862 #define __ieee754_sinhf sinhf
863 #define __ieee754_hypotf hypotf
864 #define __ieee754_j0f j0f
865 #define __ieee754_j1f j1f
866 #define __ieee754_y0f y0f
867 #define __ieee754_y1f y1f
868 #define __ieee754_jnf jnf
869 #define __ieee754_ynf ynf
870 #define __ieee754_remainderf remainderf
871 #define __ieee754_scalbf scalbf
873 #define acos fdlibm_acos
874 #define acosf fdlibm_acosf
875 #define asin fdlibm_asin
876 #define asinf fdlibm_asinf
877 #define atan fdlibm_atan
878 #define atanf fdlibm_atanf
879 #define atan2 fdlibm_atan2
880 #define cos fdlibm_cos
881 #define cosf fdlibm_cosf
882 #define sin fdlibm_sin
883 #define sinf fdlibm_sinf
884 #define tan fdlibm_tan
885 #define tanf fdlibm_tanf
886 #define cosh fdlibm_cosh
887 #define sinh fdlibm_sinh
888 #define tanh fdlibm_tanh
889 #define exp fdlibm_exp
890 #define expf fdlibm_expf
891 #define exp2 fdlibm_exp2
892 #define exp2f fdlibm_exp2f
893 #define log fdlibm_log
894 #define logf fdlibm_logf
895 #define log10 fdlibm_log10
896 #define log10f fdlibm_log10f
897 #define pow fdlibm_pow
898 #define powf fdlibm_powf
899 #define ceil fdlibm_ceil
900 #define ceilf fdlibm_ceilf
901 #define fabs fdlibm_fabs
902 #define fabsf fdlibm_fabsf
903 #define floor fdlibm_floor
904 #define acosh fdlibm_acosh
905 #define asinh fdlibm_asinh
906 #define atanh fdlibm_atanh
907 #define cbrt fdlibm_cbrt
908 #define expm1 fdlibm_expm1
909 #define hypot fdlibm_hypot
910 #define hypotf fdlibm_hypotf
911 #define log1p fdlibm_log1p
912 #define log2 fdlibm_log2
913 #define scalb fdlibm_scalb
914 #define copysign fdlibm_copysign
915 #define scalbn fdlibm_scalbn
916 #define scalbnf fdlibm_scalbnf
917 #define trunc fdlibm_trunc
918 #define truncf fdlibm_truncf
919 #define floorf fdlibm_floorf
920 #define nearbyint fdlibm_nearbyint
921 #define nearbyintf fdlibm_nearbyintf
922 #define rint fdlibm_rint
923 #define rintf fdlibm_rintf
924 #define sqrtf fdlibm_sqrtf
926 /* fdlibm kernel function */
927 int __kernel_rem_pio2(double*,double*,int,int,int);
929 /* double precision kernel functions */
930 #ifndef INLINE_REM_PIO2
931 int __ieee754_rem_pio2(double,double*);
932 #endif
933 double __kernel_sin(double,double,int);
934 double __kernel_cos(double,double);
935 double __kernel_tan(double,double,int);
936 double __ldexp_exp(double,int);
937 #ifdef _COMPLEX_H
938 double complex __ldexp_cexp(double complex,int);
939 #endif
941 /* float precision kernel functions */
942 #ifndef INLINE_REM_PIO2F
943 int __ieee754_rem_pio2f(float,double*);
944 #endif
945 #ifndef INLINE_KERNEL_SINDF
946 float __kernel_sindf(double);
947 #endif
948 #ifndef INLINE_KERNEL_COSDF
949 float __kernel_cosdf(double);
950 #endif
951 #ifndef INLINE_KERNEL_TANDF
952 float __kernel_tandf(double,int);
953 #endif
954 float __ldexp_expf(float,int);
955 #ifdef _COMPLEX_H
956 float complex __ldexp_cexpf(float complex,int);
957 #endif
959 /* long double precision kernel functions */
960 long double __kernel_sinl(long double, long double, int);
961 long double __kernel_cosl(long double, long double);
962 long double __kernel_tanl(long double, long double, int);
964 #endif /* !_MATH_PRIVATE_H_ */