annotate m4/fma.m4 @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18993
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
1 # fma.m4 serial 3
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 dnl Copyright (C) 2011-2019 Free Software Foundation, Inc.
16038
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 AC_DEFUN([gl_FUNC_FMA],
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 [
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 dnl Determine FMA_LIBM.
16611
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
12 gl_MATHFUNC([fma], [double], [(double, double, double)],
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
13 [extern
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
14 #ifdef __cplusplus
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
15 "C"
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
16 #endif
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
17 double fma (double, double, double);
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
18 ])
16038
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 if test $gl_cv_func_fma_no_libm = yes \
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 || test $gl_cv_func_fma_in_libm = yes; then
16611
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
21 dnl Also check whether it's declared.
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
22 dnl IRIX 6.5 has fma() in libm but doesn't declare it in <math.h>,
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
23 dnl and the function is buggy.
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
24 AC_CHECK_DECL([fma], , [REPLACE_FMA=1], [[#include <math.h>]])
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
25 if test $REPLACE_FMA = 0; then
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
26 gl_FUNC_FMA_WORKS
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
27 case "$gl_cv_func_fma_works" in
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
28 *no) REPLACE_FMA=1 ;;
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
29 esac
b0c15a5d5038 fma, fmaf, fmal: Override undeclared system functions on IRIX 6.5.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
30 fi
16038
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 else
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 HAVE_FMA=0
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 fi
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 if test $HAVE_FMA = 0 || test $REPLACE_FMA = 1; then
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 dnl Find libraries needed to link lib/fmal.c.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 AC_REQUIRE([gl_FUNC_FREXP])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 AC_REQUIRE([gl_FUNC_LDEXP])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 AC_REQUIRE([gl_FUNC_FEGETROUND])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 FMA_LIBM=
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 dnl Append $FREXP_LIBM to FMA_LIBM, avoiding gratuitous duplicates.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 case " $FMA_LIBM " in
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 *" $FREXP_LIBM "*) ;;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 *) FMA_LIBM="$FMA_LIBM $FREXP_LIBM" ;;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 esac
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 dnl Append $LDEXP_LIBM to FMA_LIBM, avoiding gratuitous duplicates.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 case " $FMA_LIBM " in
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 *" $LDEXP_LIBM "*) ;;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 *) FMA_LIBM="$FMA_LIBM $LDEXP_LIBM" ;;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 esac
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 dnl Append $FEGETROUND_LIBM to FMA_LIBM, avoiding gratuitous duplicates.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 case " $FMA_LIBM " in
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 *" $FEGETROUND_LIBM "*) ;;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 *) FMA_LIBM="$FMA_LIBM $FEGETROUND_LIBM" ;;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 esac
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 fi
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 AC_SUBST([FMA_LIBM])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 ])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 dnl Test whether fma() has any of the 7 known bugs of glibc 2.11.3 on x86_64.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 AC_DEFUN([gl_FUNC_FMA_WORKS],
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 [
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 AC_REQUIRE([AC_PROG_CC])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 AC_REQUIRE([gl_FUNC_LDEXP])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 save_LIBS="$LIBS"
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 LIBS="$LIBS $FMA_LIBM $LDEXP_LIBM"
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 AC_CACHE_CHECK([whether fma works], [gl_cv_func_fma_works],
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 [
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 AC_RUN_IFELSE(
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 [AC_LANG_SOURCE([[
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 #include <float.h>
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 #include <math.h>
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 double p0 = 0.0;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 int main()
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 int failed_tests = 0;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* These tests fail with glibc 2.11.3 on x86_64. */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 volatile double x = 1.5; /* 3 * 2^-1 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 volatile double y = x;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 volatile double z = ldexp (1.0, DBL_MANT_DIG + 1); /* 2^54 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 /* x * y + z with infinite precision: 2^54 + 9 * 2^-2.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 Lies between (2^52 + 0) * 2^2 and (2^52 + 1) * 2^2
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 and is closer to (2^52 + 1) * 2^2, therefore the rounding
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 must round up and produce (2^52 + 1) * 2^2. */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 volatile double expected = z + 4.0;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 if (result != expected)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 failed_tests |= 1;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 volatile double x = 1.25; /* 2^0 + 2^-2 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 volatile double y = - x;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 volatile double z = ldexp (1.0, DBL_MANT_DIG + 1); /* 2^54 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 /* x * y + z with infinite precision: 2^54 - 2^0 - 2^-1 - 2^-4.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 Lies between (2^53 - 1) * 2^1 and 2^53 * 2^1
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 and is closer to (2^53 - 1) * 2^1, therefore the rounding
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 must round down and produce (2^53 - 1) * 2^1. */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 volatile double expected = (ldexp (1.0, DBL_MANT_DIG) - 1.0) * 2.0;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 if (result != expected)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 failed_tests |= 2;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 volatile double x = 1.0 + ldexp (1.0, 1 - DBL_MANT_DIG); /* 2^0 + 2^-52 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 volatile double y = x;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 volatile double z = 4.0; /* 2^2 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 /* x * y + z with infinite precision: 2^2 + 2^0 + 2^-51 + 2^-104.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 Lies between (2^52 + 2^50) * 2^-50 and (2^52 + 2^50 + 1) * 2^-50
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 and is closer to (2^52 + 2^50 + 1) * 2^-50, therefore the rounding
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 must round up and produce (2^52 + 2^50 + 1) * 2^-50. */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 volatile double expected = 4.0 + 1.0 + ldexp (1.0, 3 - DBL_MANT_DIG);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 if (result != expected)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 failed_tests |= 4;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 volatile double x = 1.0 + ldexp (1.0, 1 - DBL_MANT_DIG); /* 2^0 + 2^-52 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 volatile double y = - x;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 volatile double z = 8.0; /* 2^3 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 /* x * y + z with infinite precision: 2^2 + 2^1 + 2^0 - 2^-51 - 2^-104.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 Lies between (2^52 + 2^51 + 2^50 - 1) * 2^-50 and
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 (2^52 + 2^51 + 2^50) * 2^-50 and is closer to
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 (2^52 + 2^51 + 2^50 - 1) * 2^-50, therefore the rounding
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 must round down and produce (2^52 + 2^51 + 2^50 - 1) * 2^-50. */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 volatile double expected = 7.0 - ldexp (1.0, 3 - DBL_MANT_DIG);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 if (result != expected)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 failed_tests |= 8;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 volatile double x = 1.25; /* 2^0 + 2^-2 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 volatile double y = - 0.75; /* - 2^0 + 2^-2 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 volatile double z = ldexp (1.0, DBL_MANT_DIG); /* 2^53 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 /* x * y + z with infinite precision: 2^53 - 2^0 + 2^-4.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 Lies between (2^53 - 2^0) and 2^53 and is closer to (2^53 - 2^0),
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 therefore the rounding must round down and produce (2^53 - 2^0). */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 volatile double expected = ldexp (1.0, DBL_MANT_DIG) - 1.0;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 if (result != expected)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 failed_tests |= 16;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 if ((DBL_MANT_DIG % 2) == 1)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 volatile double x = 1.0 + ldexp (1.0, - (DBL_MANT_DIG + 1) / 2); /* 2^0 + 2^-27 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 volatile double y = 1.0 - ldexp (1.0, - (DBL_MANT_DIG + 1) / 2); /* 2^0 - 2^-27 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 volatile double z = - ldexp (1.0, DBL_MIN_EXP - DBL_MANT_DIG); /* - 2^-1074 */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 /* x * y + z with infinite precision: 2^0 - 2^-54 - 2^-1074.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 Lies between (2^53 - 1) * 2^-53 and 2^53 * 2^-53 and is closer to
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 (2^53 - 1) * 2^-53, therefore the rounding must round down and
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 produce (2^53 - 1) * 2^-53. */
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 volatile double expected = 1.0 - ldexp (1.0, - DBL_MANT_DIG);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 if (result != expected)
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 failed_tests |= 32;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 {
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 double minus_inf = -1.0 / p0;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 volatile double x = ldexp (1.0, DBL_MAX_EXP - 1);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 volatile double y = ldexp (1.0, DBL_MAX_EXP - 1);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 volatile double z = minus_inf;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 volatile double result = fma (x, y, z);
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 if (!(result == minus_inf))
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 failed_tests |= 64;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 }
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 return failed_tests;
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 }]])],
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 [gl_cv_func_fma_works=yes],
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 [gl_cv_func_fma_works=no],
18993
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
170 [dnl Guess yes on native Windows with MSVC.
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
171 dnl Otherwise guess no, even on glibc systems.
16038
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 gl_cv_func_fma_works="guessing no"
18993
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
173 case "$host_os" in
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
174 mingw*)
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
175 AC_EGREP_CPP([Known], [
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
176 #ifdef _MSC_VER
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
177 Known
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
178 #endif
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
179 ], [gl_cv_func_fma_works="guessing yes"])
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
180 ;;
a75cfc731331 Improve cross-compilation guesses for native Windows.
Bruno Haible <bruno@clisp.org>
parents: 18626
diff changeset
181 esac
16038
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
182 ])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
183 ])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 LIBS="$save_LIBS"
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 ])
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 # Prerequisites of lib/fma.c.
8f14d00d6f24 New module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 AC_DEFUN([gl_PREREQ_FMA], [:])