PR target/83554
[official-gcc.git] / libquadmath / strtod / mpn2flt128.c
blob844ae97d834ff2ab9c87f1dfb9764d95c2d3f555
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 <config.h>
21 #include <float.h>
22 #include <math.h>
23 #include "../printf/gmp-impl.h"
25 /* Convert a multi-precision integer of the needed number of bits (113 for
26 long double) and an integral power of two to a `long double' in IEEE854
27 quad-precision format. */
29 __float128
30 mpn_construct_float128 (mp_srcptr frac_ptr, int expt, int sign)
32 ieee854_float128 u;
34 u.ieee.negative = sign;
35 u.ieee.exponent = expt + IEEE854_FLOAT128_BIAS;
36 #if BITS_PER_MP_LIMB == 32
37 u.ieee.mant_low = (((uint64_t) frac_ptr[1]) << 32)
38 | (frac_ptr[0] & 0xffffffff);
39 u.ieee.mant_high = (((uint64_t) frac_ptr[3]
40 & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 96)) - 1))
41 << 32) | (frac_ptr[2] & 0xffffffff);
42 #elif BITS_PER_MP_LIMB == 64
43 u.ieee.mant_low = frac_ptr[0];
44 u.ieee.mant_high = frac_ptr[1]
45 & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 64)) - 1);
46 #else
47 #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
48 #endif
50 return u.value;