2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128 / mpn2ldbl.c
blob37e2817dbcd972a80121e55516485d83effdb8a1
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.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include "gmp.h"
21 #include "gmp-impl.h"
22 #include <ieee754.h>
23 #include <float.h>
24 #include <math.h>
26 /* Convert a multi-precision integer of the needed number of bits (113 for
27 long double) and an integral power of two to a `long double' in IEEE854
28 quad-precision format. */
30 long double
31 __mpn_construct_long_double (mp_srcptr frac_ptr, int expt, int sign)
33 union ieee854_long_double u;
35 u.ieee.negative = sign;
36 u.ieee.exponent = expt + IEEE854_LONG_DOUBLE_BIAS;
37 #if BITS_PER_MP_LIMB == 32
38 u.ieee.mantissa3 = frac_ptr[0];
39 u.ieee.mantissa2 = frac_ptr[1];
40 u.ieee.mantissa1 = frac_ptr[2];
41 u.ieee.mantissa0 = frac_ptr[3] & (((mp_limb_t) 1
42 << (LDBL_MANT_DIG - 96)) - 1);
43 #elif BITS_PER_MP_LIMB == 64
44 u.ieee.mantissa3 = frac_ptr[0] & (((mp_limb_t) 1 << 32) - 1);
45 u.ieee.mantissa2 = frac_ptr[0] >> 32;
46 u.ieee.mantissa1 = frac_ptr[1] & (((mp_limb_t) 1 << 32) - 1);
47 u.ieee.mantissa0 = (frac_ptr[1] >> 32) & (((mp_limb_t) 1
48 << (LDBL_MANT_DIG - 96)) - 1);
49 #else
50 #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
51 #endif
53 return u.d;