~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/mpf/reldiff.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* mpf_reldiff -- Generate the relative difference of two floats.
2
2
 
3
 
Copyright 1996, 2001 Free Software Foundation, Inc.
 
3
Copyright 1996, 2001, 2004, 2005 Free Software Foundation, Inc.
4
4
 
5
5
This file is part of the GNU MP Library.
6
6
 
16
16
 
17
17
You should have received a copy of the GNU Lesser General Public License
18
18
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19
 
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
 
MA 02111-1307, USA. */
 
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
20
MA 02110-1301, USA. */
21
21
 
22
22
#include "gmp.h"
23
23
#include "gmp-impl.h"
24
24
 
 
25
 
 
26
/* The precision we use for d = x-y is based on what mpf_div will want from
 
27
   the dividend.  It calls mpn_tdiv_qr to produce a quotient of rprec+1
 
28
   limbs.  So rprec+1 == dsize - xsize + 1, hence dprec = rprec+xsize.  */
 
29
 
25
30
void
26
31
mpf_reldiff (mpf_t rdiff, mpf_srcptr x, mpf_srcptr y)
27
32
{
28
 
  if (mpf_cmp_ui (x, 0) == 0)
 
33
  if (UNLIKELY (SIZ(x) == 0))
29
34
    {
30
35
      mpf_set_ui (rdiff, (unsigned long int) (mpf_sgn (y) != 0));
31
36
    }
32
37
  else
33
38
    {
 
39
      mp_size_t dprec;
34
40
      mpf_t d;
35
 
      mp_limb_t tmp_limb[2];
36
 
 
37
 
      d->_mp_prec = 1;
38
 
      d->_mp_d = tmp_limb;
 
41
      TMP_DECL;
 
42
 
 
43
      TMP_MARK;
 
44
      dprec = PREC(rdiff) + ABSIZ(x);
 
45
      ASSERT (PREC(rdiff)+1 == dprec - ABSIZ(x) + 1);
 
46
 
 
47
      PREC(d) = dprec;
 
48
      PTR(d) = TMP_ALLOC_LIMBS (dprec + 1);
39
49
 
40
50
      mpf_sub (d, x, y);
41
 
      mpf_abs (d, d);
 
51
      SIZ(d) = ABSIZ(d);
42
52
      mpf_div (rdiff, d, x);
 
53
 
 
54
      TMP_FREE;
43
55
    }
44
56
}
45
57