You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
5.1 KiB

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