dp_fsp.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* IEEE754 floating point arithmetic
  2. * double precision: common utilities
  3. */
  4. /*
  5. * MIPS floating point support
  6. * Copyright (C) 1994-2000 Algorithmics Ltd.
  7. *
  8. * ########################################################################
  9. *
  10. * This program is free software; you can distribute it and/or modify it
  11. * under the terms of the GNU General Public License (Version 2) as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. * for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * ########################################################################
  24. */
  25. #include "ieee754dp.h"
  26. ieee754dp ieee754dp_fsp(ieee754sp x)
  27. {
  28. COMPXSP;
  29. EXPLODEXSP;
  30. CLEARCX;
  31. FLUSHXSP;
  32. switch (xc) {
  33. case IEEE754_CLASS_SNAN:
  34. SETCX(IEEE754_INVALID_OPERATION);
  35. return ieee754dp_nanxcpt(ieee754dp_indef(), "fsp");
  36. case IEEE754_CLASS_QNAN:
  37. return ieee754dp_nanxcpt(builddp(xs,
  38. DP_EMAX + 1 + DP_EBIAS,
  39. ((u64) xm
  40. << (DP_MBITS -
  41. SP_MBITS))), "fsp",
  42. x);
  43. case IEEE754_CLASS_INF:
  44. return ieee754dp_inf(xs);
  45. case IEEE754_CLASS_ZERO:
  46. return ieee754dp_zero(xs);
  47. case IEEE754_CLASS_DNORM:
  48. /* normalize */
  49. while ((xm >> SP_MBITS) == 0) {
  50. xm <<= 1;
  51. xe--;
  52. }
  53. break;
  54. case IEEE754_CLASS_NORM:
  55. break;
  56. }
  57. /* CAN'T possibly overflow,underflow, or need rounding
  58. */
  59. /* drop the hidden bit */
  60. xm &= ~SP_HIDDEN_BIT;
  61. return builddp(xs, xe + DP_EBIAS,
  62. (u64) xm << (DP_MBITS - SP_MBITS));
  63. }