[BACK]Return to set_d.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / gmp-2.0.2-ssh-2 / mpz

Annotation of OpenXM/src/kan96xx/gmp-2.0.2-ssh-2/mpz/set_d.c, Revision 1.1.1.1

1.1       takayama    1: /* mpz_set_d(integer, val) -- Assign INTEGER with a double value VAL.
                      2:
                      3: Copyright (C) 1995 Free Software Foundation, Inc.
                      4:
                      5: This file is part of the GNU MP Library.
                      6:
                      7: The GNU MP Library is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU Library General Public License as published by
                      9: the Free Software Foundation; either version 2 of the License, or (at your
                     10: option) any later version.
                     11:
                     12: The GNU MP Library is distributed in the hope that it will be useful, but
                     13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     14: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
                     15: License for more details.
                     16:
                     17: You should have received a copy of the GNU Library General Public License
                     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. */
                     21:
                     22: #include "gmp.h"
                     23: #include "gmp-impl.h"
                     24:
                     25: void
                     26: #if __STDC__
                     27: mpz_set_d (mpz_ptr r, double d)
                     28: #else
                     29: mpz_set_d (r, d)
                     30:      mpz_ptr r;
                     31:      double d;
                     32: #endif
                     33: {
                     34:   int negative;
                     35:   mp_size_t size;
                     36:   mp_limb_t tp[3];
                     37:   mp_ptr rp;
                     38:
                     39:   negative = d < 0;
                     40:   d = ABS (d);
                     41:
                     42:   /* Handle small arguments quickly.  */
                     43:   if (d < MP_BASE_AS_DOUBLE)
                     44:     {
                     45:       mp_limb_t tmp;
                     46:       tmp = d;
                     47:       PTR(r)[0] = tmp;
                     48:       SIZ(r) = negative ? -(tmp != 0) : (tmp != 0);
                     49:       return;
                     50:     }
                     51:
                     52:   size = __gmp_extract_double (tp, d);
                     53:
                     54:   if (ALLOC(r) < size)
                     55:     _mpz_realloc (r, size);
                     56:
                     57:   rp = PTR (r);
                     58:
                     59: #if BITS_PER_MP_LIMB == 32
                     60:   switch (size)
                     61:     {
                     62:     default:
                     63:       MPN_ZERO (rp, size - 3);
                     64:       rp += size - 3;
                     65:     case 3:
                     66:       rp[2] = tp[2];
                     67:       rp[1] = tp[1];
                     68:       rp[0] = tp[0];
                     69:       break;
                     70:     case 2:
                     71:       rp[1] = tp[2];
                     72:       rp[0] = tp[1];
                     73:       break;
                     74:     case 1:
                     75:       abort ();
                     76:     }
                     77: #else
                     78:   switch (size)
                     79:     {
                     80:     default:
                     81:       MPN_ZERO (rp, size - 2);
                     82:       rp += size - 2;
                     83:     case 2:
                     84:       rp[1] = tp[1];
                     85:       rp[0] = tp[0];
                     86:       break;
                     87:     case 1:
                     88:       abort ();
                     89:     }
                     90: #endif
                     91:
                     92:   SIZ(r) = negative ? -size : size;
                     93: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>