ieee754.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* ieee754 floating point arithmetic
  2. * single and double precision
  3. *
  4. * BUGS
  5. * not much dp done
  6. * doesn't generate IEEE754_INEXACT
  7. *
  8. */
  9. /*
  10. * MIPS floating point support
  11. * Copyright (C) 1994-2000 Algorithmics Ltd.
  12. *
  13. * This program is free software; you can distribute it and/or modify it
  14. * under the terms of the GNU General Public License (Version 2) as
  15. * published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope it will be useful, but WITHOUT
  18. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  20. * for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  25. */
  26. #include <linux/compiler.h>
  27. #include "ieee754.h"
  28. #include "ieee754sp.h"
  29. #include "ieee754dp.h"
  30. /*
  31. * Special constants
  32. */
  33. /*
  34. * Older GCC requires the inner braces for initialization of union ieee754dp's
  35. * anonymous struct member. Without an error will result.
  36. */
  37. #define xPCNST(s, b, m, ebias) \
  38. { \
  39. { \
  40. .sign = (s), \
  41. .bexp = (b) + ebias, \
  42. .mant = (m) \
  43. } \
  44. }
  45. #define DPCNST(s, b, m) \
  46. xPCNST(s, b, m, DP_EBIAS)
  47. const union ieee754dp __ieee754dp_spcvals[] = {
  48. DPCNST(0, DP_EMIN - 1, 0x0000000000000ULL), /* + zero */
  49. DPCNST(1, DP_EMIN - 1, 0x0000000000000ULL), /* - zero */
  50. DPCNST(0, 0, 0x0000000000000ULL), /* + 1.0 */
  51. DPCNST(1, 0, 0x0000000000000ULL), /* - 1.0 */
  52. DPCNST(0, 3, 0x4000000000000ULL), /* + 10.0 */
  53. DPCNST(1, 3, 0x4000000000000ULL), /* - 10.0 */
  54. DPCNST(0, DP_EMAX + 1, 0x0000000000000ULL), /* + infinity */
  55. DPCNST(1, DP_EMAX + 1, 0x0000000000000ULL), /* - infinity */
  56. DPCNST(0, DP_EMAX + 1, 0x7FFFFFFFFFFFFULL), /* + indef quiet Nan */
  57. DPCNST(0, DP_EMAX, 0xFFFFFFFFFFFFFULL), /* + max */
  58. DPCNST(1, DP_EMAX, 0xFFFFFFFFFFFFFULL), /* - max */
  59. DPCNST(0, DP_EMIN, 0x0000000000000ULL), /* + min normal */
  60. DPCNST(1, DP_EMIN, 0x0000000000000ULL), /* - min normal */
  61. DPCNST(0, DP_EMIN - 1, 0x0000000000001ULL), /* + min denormal */
  62. DPCNST(1, DP_EMIN - 1, 0x0000000000001ULL), /* - min denormal */
  63. DPCNST(0, 31, 0x0000000000000ULL), /* + 1.0e31 */
  64. DPCNST(0, 63, 0x0000000000000ULL), /* + 1.0e63 */
  65. };
  66. #define SPCNST(s, b, m) \
  67. xPCNST(s, b, m, SP_EBIAS)
  68. const union ieee754sp __ieee754sp_spcvals[] = {
  69. SPCNST(0, SP_EMIN - 1, 0x000000), /* + zero */
  70. SPCNST(1, SP_EMIN - 1, 0x000000), /* - zero */
  71. SPCNST(0, 0, 0x000000), /* + 1.0 */
  72. SPCNST(1, 0, 0x000000), /* - 1.0 */
  73. SPCNST(0, 3, 0x200000), /* + 10.0 */
  74. SPCNST(1, 3, 0x200000), /* - 10.0 */
  75. SPCNST(0, SP_EMAX + 1, 0x000000), /* + infinity */
  76. SPCNST(1, SP_EMAX + 1, 0x000000), /* - infinity */
  77. SPCNST(0, SP_EMAX + 1, 0x3FFFFF), /* + indef quiet Nan */
  78. SPCNST(0, SP_EMAX, 0x7FFFFF), /* + max normal */
  79. SPCNST(1, SP_EMAX, 0x7FFFFF), /* - max normal */
  80. SPCNST(0, SP_EMIN, 0x000000), /* + min normal */
  81. SPCNST(1, SP_EMIN, 0x000000), /* - min normal */
  82. SPCNST(0, SP_EMIN - 1, 0x000001), /* + min denormal */
  83. SPCNST(1, SP_EMIN - 1, 0x000001), /* - min denormal */
  84. SPCNST(0, 31, 0x000000), /* + 1.0e31 */
  85. SPCNST(0, 63, 0x000000), /* + 1.0e63 */
  86. };