mpn2flt128.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (C) 1995,1996,1997,1998,1999,2002,2003
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <config.h>
  17. #include <float.h>
  18. #include <math.h>
  19. #include "../printf/gmp-impl.h"
  20. /* Convert a multi-precision integer of the needed number of bits (113 for
  21. long double) and an integral power of two to a `long double' in IEEE854
  22. quad-precision format. */
  23. __float128
  24. mpn_construct_float128 (mp_srcptr frac_ptr, int expt, int sign)
  25. {
  26. ieee854_float128 u;
  27. u.ieee.negative = sign;
  28. u.ieee.exponent = expt + IEEE854_FLOAT128_BIAS;
  29. #if BITS_PER_MP_LIMB == 32
  30. u.ieee.mant_low = (((uint64_t) frac_ptr[1]) << 32)
  31. | (frac_ptr[0] & 0xffffffff);
  32. u.ieee.mant_high = (((uint64_t) frac_ptr[3]
  33. & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 96)) - 1))
  34. << 32) | (frac_ptr[2] & 0xffffffff);
  35. #elif BITS_PER_MP_LIMB == 64
  36. u.ieee.mant_low = frac_ptr[0];
  37. u.ieee.mant_high = frac_ptr[1]
  38. & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 64)) - 1);
  39. #else
  40. #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
  41. #endif
  42. return u.value;
  43. }