c++: Add fixed test [PR71424]
[official-gcc.git] / libquadmath / strtod / mpn2flt128.c
blob33cdb6232cd8c21ccad18270b59d12147c649f0f
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.mantissa3 = frac_ptr[0];
38 u.ieee.mantissa2 = frac_ptr[1];
39 u.ieee.mantissa1 = frac_ptr[2];
40 u.ieee.mantissa0 = frac_ptr[3] & (((mp_limb_t) 1
41 << (FLT128_MANT_DIG - 96)) - 1);
42 #elif BITS_PER_MP_LIMB == 64
43 u.ieee.mantissa3 = frac_ptr[0] & (((mp_limb_t) 1 << 32) - 1);
44 u.ieee.mantissa2 = frac_ptr[0] >> 32;
45 u.ieee.mantissa1 = frac_ptr[1] & (((mp_limb_t) 1 << 32) - 1);
46 u.ieee.mantissa0 = (frac_ptr[1] >> 32) & (((mp_limb_t) 1
47 << (FLT128_MANT_DIG - 96)) - 1);
48 #else
49 #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
50 #endif
52 return u.value;