version 1.1.1.2, 2000/09/09 14:13:08 |
version 1.1.1.3, 2003/08/25 16:06:34 |
|
|
/* mpf_set_q (mpf_t rop, mpq_t op) -- Convert the rational op to the float rop. |
/* mpf_set_q (mpf_t rop, mpq_t op) -- Convert the rational op to the float rop. |
|
|
Copyright (C) 1996, 1999 Free Software Foundation, Inc. |
Copyright 1996, 1999, 2001, 2002 Free Software Foundation, Inc. |
|
|
This file is part of the GNU MP Library. |
This file is part of the GNU MP Library. |
|
|
Line 24 MA 02111-1307, USA. */ |
|
Line 24 MA 02111-1307, USA. */ |
|
#include "longlong.h" |
#include "longlong.h" |
|
|
void |
void |
#if __STDC__ |
|
mpf_set_q (mpf_t r, mpq_srcptr q) |
mpf_set_q (mpf_t r, mpq_srcptr q) |
#else |
|
mpf_set_q (r, q) |
|
mpf_t r; |
|
mpq_srcptr q; |
|
#endif |
|
{ |
{ |
mp_ptr np, dp; |
mp_ptr np, dp; |
mp_ptr rp; |
mp_ptr rp; |
mp_size_t nsize, dsize; |
mp_size_t nsize, dsize; |
mp_size_t qsize, rsize; |
mp_size_t qsize, rsize; |
mp_size_t sign_quotient; |
mp_size_t sign_quotient; |
unsigned normalization_steps; |
|
mp_limb_t qlimb; |
mp_limb_t qlimb; |
mp_ptr qp; |
mp_ptr qp; |
mp_size_t prec; |
mp_size_t prec; |
|
|
rsize = MAX (nsize, dsize); |
rsize = MAX (nsize, dsize); |
rp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB); |
rp = (mp_ptr) TMP_ALLOC ((rsize + 1) * BYTES_PER_MP_LIMB); |
|
|
count_leading_zeros (normalization_steps, dp[dsize - 1]); |
|
|
|
/* Normalize the denominator, i.e. make its most significant bit set by |
/* Normalize the denominator, i.e. make its most significant bit set by |
shifting it NORMALIZATION_STEPS bits to the left. Also shift the |
shifting it NORMALIZATION_STEPS bits to the left. Also shift the |
numerator the same number of steps (to keep the quotient the same!). */ |
numerator the same number of steps (to keep the quotient the same!). */ |
if (normalization_steps != 0) |
if ((dp[dsize - 1] & GMP_NUMB_HIGHBIT) == 0) |
{ |
{ |
mp_ptr tp; |
mp_ptr tp; |
mp_limb_t nlimb; |
mp_limb_t nlimb; |
|
unsigned normalization_steps; |
|
|
|
count_leading_zeros (normalization_steps, dp[dsize - 1]); |
|
normalization_steps -= GMP_NAIL_BITS; |
|
|
/* Shift up the denominator setting the most significant bit of |
/* Shift up the denominator setting the most significant bit of |
the most significant limb. Use temporary storage not to clobber |
the most significant limb. Use temporary storage not to clobber |