]> git.ipfire.org Git - thirdparty/gcc.git/blob - libquadmath/strtod/mpn2flt128.c
Update copyright in libquadmath.
[thirdparty/gcc.git] / libquadmath / strtod / mpn2flt128.c
1 /* Copyright (C) 1995-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19 #include <config.h>
20 #include <float.h>
21 #include <math.h>
22 #include "../printf/gmp-impl.h"
23
24 /* Convert a multi-precision integer of the needed number of bits (113 for
25 long double) and an integral power of two to a `long double' in IEEE854
26 quad-precision format. */
27
28 __float128
29 mpn_construct_float128 (mp_srcptr frac_ptr, int expt, int sign)
30 {
31 ieee854_float128 u;
32
33 u.ieee.negative = sign;
34 u.ieee.exponent = expt + IEEE854_FLOAT128_BIAS;
35 #if BITS_PER_MP_LIMB == 32
36 u.ieee.mant_low = (((uint64_t) frac_ptr[1]) << 32)
37 | (frac_ptr[0] & 0xffffffff);
38 u.ieee.mant_high = (((uint64_t) frac_ptr[3]
39 & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 96)) - 1))
40 << 32) | (frac_ptr[2] & 0xffffffff);
41 #elif BITS_PER_MP_LIMB == 64
42 u.ieee.mant_low = frac_ptr[0];
43 u.ieee.mant_high = frac_ptr[1]
44 & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 64)) - 1);
45 #else
46 #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
47 #endif
48
49 return u.value;
50 }