Back to index

glibc  2.9
mpn2ldbl.c
Go to the documentation of this file.
00001 /* Copyright (C) 1995,1996,1997,1998,1999,2002,2003
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include "gmp.h"
00021 #include "gmp-impl.h"
00022 #include <ieee754.h>
00023 #include <float.h>
00024 #include <math.h>
00025 
00026 /* Convert a multi-precision integer of the needed number of bits (113 for
00027    long double) and an integral power of two to a `long double' in IEEE854
00028    quad-precision format.  */
00029 
00030 long double
00031 __mpn_construct_long_double (mp_srcptr frac_ptr, int expt, int sign)
00032 {
00033   union ieee854_long_double u;
00034 
00035   u.ieee.negative = sign;
00036   u.ieee.exponent = expt + IEEE854_LONG_DOUBLE_BIAS;
00037 #if BITS_PER_MP_LIMB == 32
00038   u.ieee.mantissa3 = frac_ptr[0];
00039   u.ieee.mantissa2 = frac_ptr[1];
00040   u.ieee.mantissa1 = frac_ptr[2];
00041   u.ieee.mantissa0 = frac_ptr[3] & (((mp_limb_t) 1
00042                                  << (LDBL_MANT_DIG - 96)) - 1);
00043 #elif BITS_PER_MP_LIMB == 64
00044   u.ieee.mantissa3 = frac_ptr[0] & (((mp_limb_t) 1 << 32) - 1);
00045   u.ieee.mantissa2 = frac_ptr[0] >> 32;
00046   u.ieee.mantissa1 = frac_ptr[1] & (((mp_limb_t) 1 << 32) - 1);
00047   u.ieee.mantissa0 = (frac_ptr[1] >> 32) & (((mp_limb_t) 1
00048                                         << (LDBL_MANT_DIG - 96)) - 1);
00049 #else
00050   #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for"
00051 #endif
00052 
00053   return u.d;
00054 }