]> www.ginac.de Git - cln.git/blob - m4/floatparam.m4
Fix yet another dependent base C++ language issue.
[cln.git] / m4 / floatparam.m4
1 # floatparam.m4 serial 1
2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl From Bruno Haible.
8
9 AC_DEFUN([CL_FLOATPARAM_CROSS],
10 [
11   AC_REQUIRE([CL_LONGDOUBLE])
12   cl_machine_file_h=$1
13   {
14     echo "/* Rounding modes, for use below */"
15     echo "#define rounds_to_nearest        0  /* 0.5 ulp */"
16     echo "#define rounds_to_zero           1  /* 1 ulp */"
17     echo "#define rounds_to_infinity       2  /* 1 ulp */"
18     echo "#define rounds_to_minus_infinity 3  /* 1 ulp */"
19     echo
20     for type in float double "`if test $cl_cv_c_longdouble = yes; then echo 'long double'; fi`"; do
21       if test -n "$type"; then
22         epsilon_bits=-1; y="($type)1.0"
23         while true; do
24           AC_TRY_COMPILE([],
25             [typedef int verify[2*(
26                (($type)(($type)1.0 + ($type)($y)) == ($type)1.0)
27                || ($type)(($type)(($type)1.0 + ($type)($y)) - ($type)1.0) != ($type)($y)
28              ) - 1];],
29             [break;])
30           epsilon_bits=`expr $epsilon_bits + 1`; y="$y * ($type)0.5"
31         done
32         negepsilon_bits=-1; y="($type)-1.0"
33         while true; do
34           AC_TRY_COMPILE([],
35             [typedef int verify[2*(
36                (($type)(($type)1.0 + ($type)($y)) == ($type)1.0)
37                || ($type)(($type)(($type)1.0 + ($type)($y)) - ($type)1.0) != ($type)($y)
38              ) - 1];],
39             [break;])
40           negepsilon_bits=`expr $negepsilon_bits + 1`; y="$y * ($type)0.5"
41         done
42         echo "/* Properties of type \`$type': */"
43         echo "/* Largest n for which 1+2^(-n) is exactly represented is $epsilon_bits. */"
44         echo "/* Largest n for which 1-2^(-n) is exactly represented is $negepsilon_bits. */"
45         if test `expr $negepsilon_bits '<=' $epsilon_bits` = 1; then
46           echo "#error \"No exponent jump at 1.0 for type $type!\""
47         else
48           if test `expr $negepsilon_bits '>' $epsilon_bits + 1` = 1; then
49             echo "/* Base for type '$type' is 2^"`expr $negepsilon_bits - $epsilon_bits`
50           fi
51           echo "#define "`echo $type | sed -e 's, ,_,g'`"_mant_bits "`expr $epsilon_bits + 1`
52         fi
53         x="($type)1.0"
54         i=$epsilon_bits
55         while test $i != 0; do
56           x="$x * ($type)0.5"
57           i=`expr $i - 1`
58         done
59         x="($type)($x)"
60         y1="($type)(($type)1.0 + ($type)5.0*$x)"
61         y2="($type)(($type)1.0 + ($type)6.0*$x)"
62         ys1="($type)(($type)1.0 + ($type)5.4*$x)"
63         ys2="($type)(($type)1.0 + ($type)5.6*$x)"
64         z1="($type)(($type)-1.0 + ($type)(-5.0)*$x)"
65         z2="($type)(($type)-1.0 + ($type)(-6.0)*$x)"
66         zs1="($type)(($type)-1.0 + ($type)(-5.4)*$x)"
67         zs2="($type)(($type)-1.0 + ($type)(-5.6)*$x)"
68         rounds=
69         if test -z "$rounds"; then
70           AC_TRY_COMPILE([],
71             [typedef int verify[2*(
72                $ys1 == $y1 && $ys2 == $y2 && $zs1 == $z1 && $zs2 == $z2
73              ) - 1];],
74             [rounds=rounds_to_nearest])
75         fi
76         if test -z "$rounds"; then
77           AC_TRY_COMPILE([],
78             [typedef int verify[2*(
79                $ys1 == $y1 && $ys2 == $y1 && $zs1 == $z1 && $zs2 == $z1
80              ) - 1];],
81             [rounds=rounds_to_zero])
82         fi
83         if test -z "$rounds"; then
84           AC_TRY_COMPILE([],
85             [typedef int verify[2*(
86                $ys1 == $y2 && $ys2 == $y2 && $zs1 == $z1 && $zs2 == $z1
87              ) - 1];],
88             [rounds=rounds_to_infinity])
89         fi
90         if test -z "$rounds"; then
91           AC_TRY_COMPILE([],
92             [typedef int verify[2*(
93                $ys1 == $y1 && $ys2 == $y1 && $zs1 == $z2 && $zs2 == $z2
94              ) - 1];],
95             [rounds=rounds_to_minus_infinity])
96         fi
97         if test -n "$rounds"; then
98           echo "#define "`echo $type | sed -e 's, ,_,g'`"_rounds $rounds"
99         else
100           echo "#error \"Unknown rounding mode for type $type!\""
101         fi
102         echo
103       fi
104     done
105     dnl Words-in-a-double endianness test. Note that, assuming IEEE 754 format,
106     dnl 2.5479915693083957     = { 0x40 0x04 0x62 0x49 0x67 0x65 0x4E 0x64 } ..bIgeNd
107     dnl 1.4396527506122064e164 = { 0x62 0x04 0x00 0x00 0x4E 0x65 0x67 0x49 } b...NegI
108     dnl 2.5495230282078065     = { 0x40 0x04 0x65 0x6C 0x54 0x54 0x69 0x4C } ..elTTiL
109     dnl 1.4139248369879473e214 = { 0x6C 0x65 0x00 0x00 0x4C 0x69 0x54 0x54 } le..LiTT
110     double_wordorder_bigendian_p=
111     AC_TRY_COMPILE([double a[9] = {
112        0, 2.5479915693083957, 0, 1.4396527506122064e164,
113        0, 2.5495230282078065, 0, 1.4139248369879473e214,
114        0 };], [], [
115       if grep LiTTle conftest.$ac_objext >/dev/null ; then
116         double_wordorder_bigendian_p=0
117       else
118         if grep bIgeN conftest.$ac_objext >/dev/null ; then
119           double_wordorder_bigendian_p=1
120         fi
121       fi])
122     if test -n "$double_wordorder_bigendian_p"; then
123       echo "#define double_wordorder_bigendian_p $double_wordorder_bigendian_p"
124     else
125       echo "/* Dazed and confused!  Better not define anything. */"
126     fi
127     echo
128   } > "$cl_machine_file_h"
129 ])