Rearrange the file tree.
[u/mdw/catacomb] / mpint.h
diff --git a/mpint.h b/mpint.h
deleted file mode 100644 (file)
index dbf9065..0000000
--- a/mpint.h
+++ /dev/null
@@ -1,192 +0,0 @@
-/* -*-c-*-
- *
- * $Id$
- *
- * Conversion between MPs and standard C integers
- *
- * (c) 1999 Straylight/Edgeware
- */
-
-/*----- Licensing notice --------------------------------------------------*
- *
- * This file is part of Catacomb.
- *
- * Catacomb is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * Catacomb is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with Catacomb; if not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- * MA 02111-1307, USA.
- */
-
-#ifndef CATACOMB_MPINT_H
-#define CATACOMB_MPINT_H
-
-#ifdef __cplusplus
-  extern "C" {
-#endif
-
-/*----- Header files ------------------------------------------------------*/
-
-#include <limits.h>
-
-#ifndef CATACOMB_MP_H
-#  include "mp.h"
-#endif
-
-/*----- Generic translation macros ----------------------------------------*/
-
-/* --- @MP_FROMINT@ --- *
- *
- * Arguments:  @d@ = destination multiprecision integer
- *             @type@ = type of integer which @i@ is
- *             @i@ = a standard C integer
- *
- * Use:                Stores the value of @i@ in @d@.  This macro is actually
- *             rather subtle in places.  Be careful what you change.
- */
-
-#define MP_FROMINT(d, type, i) do {                                    \
-  type _i = (i);                                                       \
-  size_t _o = 0;                                                       \
-  mp *_d = (d);                                                                \
-  size_t _sz = 4;                                                      \
-                                                                       \
-  MP_DEST(_d, _sz, 0);                                                 \
-  _d->f &= ~(MP_NEG | MP_UNDEF);                                       \
-                                                                       \
-  if (_i >= 0) {                                                       \
-    while (_i) {                                                       \
-      if (_o == _sz) {                                                 \
-       _sz <<= 1;                                                      \
-       MP_ENSURE(_d, _sz);                                             \
-      }                                                                        \
-      _d->v[_o++] = MPW(_i);                                           \
-      if (_i <= MPW_MAX)                                               \
-       break;                                                          \
-      else                                                             \
-       _i /= (type)MPW_MAX + 1;                                        \
-    }                                                                  \
-  } else {                                                             \
-    _d->f |= MP_NEG;                                                   \
-    while (_i) {                                                       \
-      if (_o == _sz) {                                                 \
-       _sz <<= 1;                                                      \
-       MP_ENSURE(_d, _sz);                                             \
-      }                                                                        \
-      _d->v[_o++] = MPW(-_i);                                          \
-      if (_i >= -MPW_MAX)                                              \
-       break;                                                          \
-      else                                                             \
-       _i /= (type)MPW_MAX + 1;                                        \
-    }                                                                  \
-  }                                                                    \
-                                                                       \
-  _d->vl = _d->v + _o;                                                 \
-  (d) = _d;                                                            \
-} while (0)
-
-/* --- @MP_TOINT@ --- *
- *
- * Arguments:  @m@ = a multiprecision integer
- *             @type@ = the type of @i@
- *             @max@ = the largest value @i@ can represent
- *             @i@ = an integer variable
- *
- * Use:                Stores the value of a multiprecision integer in a standard C
- *             integer.  If the value won't fit, the behaviour is determined
- *             by the type of @i@: if @i@ is unsigned, the value of the
- *             multiprecision integer modulo @max + 1@ is stored; if @i@ is
- *             signed, the behaviour is undefined.
- *
- *             If you don't want to be bitten by these sorts of things, keep
- *             copies of @INT_MAX@ or whatever is appropriate in
- *             multiprecision form and compare before conversion.
- */
-
-#define MP_TOINT(m, type, max, i) do {                                 \
-  type _i = 0;                                                         \
-  type _max = (max);                                                   \
-  unsigned _s = 0;                                                     \
-  const mp *_m = (m);                                                  \
-  const mpw *_v = _m->v, *_vl = _m->vl;                                        \
-                                                                       \
-  /* --- Do all the arithmetic in negative numbers --- */              \
-                                                                       \
-  while (_v < _vl && _max > 0) {                                       \
-    _i -= *_v << _s;                                                   \
-    _s += MPW_BITS;                                                    \
-    _v++;                                                              \
-    _max /= (mpd)MPW_MAX + 1;                                          \
-  }                                                                    \
-  if (!MP_NEGP(_m))                                                    \
-    _i = -_i;                                                          \
-  (i) = _i;                                                            \
-} while (0)
-
-/*----- Functions provided ------------------------------------------------*/
-
-/* --- @mp_fromINT@ --- *
- *
- * Arguments:  @mp *d@ = pointer to destination multiprecision integer
- *             @INT i@ = standard C integer to convert
- *
- * Returns:    The resulting multiprecision integer.
- *
- * Use:                Converts a standard C integer to a multiprecision integer.
- */
-
-#define mp_fromINT(name, type)                                         \
-  extern mp *mp_from##name(mp */*d*/, type /*i*/)
-
-mp_fromINT(short, short);
-mp_fromINT(ushort, unsigned short);
-mp_fromINT(int, int);
-mp_fromINT(uint, unsigned);
-mp_fromINT(uint32, uint32);
-mp_fromINT(long, long);
-mp_fromINT(ulong, unsigned long);
-
-#undef mp_fromINT
-
-/* --- @mp_toINT@ --- *
- *
- * Arguments:  @const mp *m@ = pointer to a multiprecision integer
- *
- * Returns:    The value of the integer @m@ as a C integer.
- *
- * Use:                Converts a multiprecision integer to a standard C integer.
- *             If the value of the multiprecision integer cannot be
- *             represented in the return type, and the return type is
- *             unsigned, it is reduced modulo @TYPE_MAX + 1@; if the return
- *             type is signed, the behaviour is undefined.
- */
-
-#define mp_toINT(name, type)                                           \
-  extern type mp_to##name(const mp */*m*/)
-
-mp_toINT(short, short);
-mp_toINT(ushort, unsigned short);
-mp_toINT(int, int);
-mp_toINT(uint, unsigned);
-mp_toINT(uint32, uint32);
-mp_toINT(long, long);
-mp_toINT(ulong, unsigned long);
-
-#undef mp_toINT
-
-/*----- That's all, folks -------------------------------------------------*/
-
-#ifdef __cplusplus
-  }
-#endif
-
-#endif