projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix output for large numbers.
[u/mdw/catacomb]
/
mp.h
diff --git
a/mp.h
b/mp.h
index
dce8128
..
a80a8e3
100644
(file)
--- a/
mp.h
+++ b/
mp.h
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mp.h,v 1.
5 1999/11/22 20:50:37
mdw Exp $
+ * $Id: mp.h,v 1.
6 1999/12/10 23:19:46
mdw Exp $
*
* Simple multiprecision arithmetic
*
*
* Simple multiprecision arithmetic
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mp.h,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mp.h,v $
+ * Revision 1.6 1999/12/10 23:19:46 mdw
+ * Minor bugfixes. New interface for suggested destinations.
+ *
* Revision 1.5 1999/11/22 20:50:37 mdw
* Add support for computing Jacobi symbols.
*
* Revision 1.5 1999/11/22 20:50:37 mdw
* Add support for computing Jacobi symbols.
*
@@
-44,8
+47,8
@@
*
*/
*
*/
-#ifndef MP_H
-#define MP_H
+#ifndef
CATACOMB_
MP_H
+#define
CATACOMB_
MP_H
#ifdef __cplusplus
extern "C" {
#ifdef __cplusplus
extern "C" {
@@
-58,11
+61,11
@@
#include <mLib/sub.h>
#include <mLib/sub.h>
-#ifndef MPW_H
+#ifndef
CATACOMB_
MPW_H
# include "mpw.h"
#endif
# include "mpw.h"
#endif
-#ifndef MPX_H
+#ifndef
CATACOMB_
MPX_H
# include "mpx.h"
#endif
# include "mpx.h"
#endif
@@
-79,6
+82,7
@@
typedef struct mp {
#define MP_BURN 2u
#define MP_CONST 4u
#define MP_UNDEF 8u
#define MP_BURN 2u
#define MP_CONST 4u
#define MP_UNDEF 8u
+#define MP_DESTROYED 16u
/*----- Useful constants --------------------------------------------------*/
/*----- Useful constants --------------------------------------------------*/
@@
-97,7
+101,7
@@
extern mp mp_const[];
/*----- Memory allocation hooks -------------------------------------------*/
/*----- Memory allocation hooks -------------------------------------------*/
-#ifndef MPARENA_H
+#ifndef
CATACOMB_
MPARENA_H
# include "mparena.h"
#endif
# include "mparena.h"
#endif
@@
-287,7
+291,8
@@
extern void mp_resize(mp */*m*/, size_t /*sz*/);
size_t _sz = (ssz); \
size_t _len = MP_LEN(_m); \
mpw *_v = MP_ALLOC(_sz); \
size_t _sz = (ssz); \
size_t _len = MP_LEN(_m); \
mpw *_v = MP_ALLOC(_sz); \
- memcpy(_v, _m->v, MPWS(_len)); \
+ if (!(_m->f & MP_UNDEF)) \
+ memcpy(_v, _m->v, MPWS(_len)); \
if (_m->f & MP_BURN) \
memset(_m->v, 0, MPWS(_m->sz)); \
MP_FREE(_m->v); \
if (_m->f & MP_BURN) \
memset(_m->v, 0, MPWS(_m->sz)); \
MP_FREE(_m->v); \
@@
-315,10
+320,9
@@
extern void mp_ensure(mp */*m*/, size_t /*sz*/);
size_t _len = MP_LEN(_mm); \
if (_ssz > _mm->sz) \
MP_RESIZE(_mm, _ssz); \
size_t _len = MP_LEN(_mm); \
if (_ssz > _mm->sz) \
MP_RESIZE(_mm, _ssz); \
- if (!(_mm->f & MP_UNDEF) && _ssz > _len)
{
\
+ if (!(_mm->f & MP_UNDEF) && _ssz > _len)
\
memset(_mm->vl, 0, MPWS(_ssz - _len)); \
memset(_mm->vl, 0, MPWS(_ssz - _len)); \
- _mm->vl = _mm->v + _ssz; \
- } \
+ _mm->vl = _mm->v + _ssz; \
} while (0)
/* --- @mp_modify@ --- *
} while (0)
/* --- @mp_modify@ --- *
@@
-338,13
+342,12
@@
extern mp *mp_modify(mp */*m*/, size_t /*sz*/);
#define MP_MODIFY(m, sz) do { \
size_t _rq = (sz); \
mp *_m = (m); \
#define MP_MODIFY(m, sz) do { \
size_t _rq = (sz); \
mp *_m = (m); \
- if (_m == MP_NEW) \
+ if (_m == MP_NEW || m->ref > 1 || (_m->f & MP_CONST)) { \
+ if (_m) \
+ MP_DROP(_m); \
_m = mp_create(_rq); \
_m = mp_create(_rq); \
- else { \
- MP_SPLIT(_m); \
+ } else \
MP_ENSURE(_m, _rq); \
MP_ENSURE(_m, _rq); \
- } \
- _m->vl = _m->v + _rq; \
(m) = _m; \
} while (0)
(m) = _m; \
} while (0)
@@
-388,7
+391,7
@@
extern void mp_minimize(mp */*m*/);
/*----- Bit scanning ------------------------------------------------------*/
/*----- Bit scanning ------------------------------------------------------*/
-#ifndef MPSCAN_H
+#ifndef
CATACOMB_
MPSCAN_H
# include "mpscan.h"
#endif
# include "mpscan.h"
#endif
@@
-540,24
+543,24
@@
extern mp *mp_sm(mp */*d*/, mp */*a*/);
/* --- @mp_lsl@ --- *
*
* Arguments: @mp *d@ = destination
/* --- @mp_lsl@ --- *
*
* Arguments: @mp *d@ = destination
- * @
const
mp *a@ = source
+ * @mp *a@ = source
* @size_t n@ = number of bits to move
*
* Returns: Result, @a@ shifted left by @n@.
*/
* @size_t n@ = number of bits to move
*
* Returns: Result, @a@ shifted left by @n@.
*/
-extern mp *mp_lsl(mp */*d*/,
const
mp */*a*/, size_t /*n*/);
+extern mp *mp_lsl(mp */*d*/, mp */*a*/, size_t /*n*/);
/* --- @mp_lsr@ --- *
*
* Arguments: @mp *d@ = destination
/* --- @mp_lsr@ --- *
*
* Arguments: @mp *d@ = destination
- * @
const
mp *a@ = source
+ * @mp *a@ = source
* @size_t n@ = number of bits to move
*
* Returns: Result, @a@ shifted left by @n@.
*/
* @size_t n@ = number of bits to move
*
* Returns: Result, @a@ shifted left by @n@.
*/
-extern mp *mp_lsr(mp */*d*/,
const
mp */*a*/, size_t /*n*/);
+extern mp *mp_lsr(mp */*d*/, mp */*a*/, size_t /*n*/);
/* --- @mp_cmp@ --- *
*
/* --- @mp_cmp@ --- *
*
@@
-574,54
+577,53
@@
extern int mp_cmp(const mp */*a*/, const mp */*b*/);
/* --- @mp_add@ --- *
*
* Arguments: @mp *d@ = destination
/* --- @mp_add@ --- *
*
* Arguments: @mp *d@ = destination
- * @
const
mp *a, *b@ = sources
+ * @mp *a, *b@ = sources
*
* Returns: Result, @a@ added to @b@.
*/
*
* Returns: Result, @a@ added to @b@.
*/
-extern mp *mp_add(mp */*d*/,
const mp */*a*/, const
mp */*b*/);
+extern mp *mp_add(mp */*d*/,
mp */*a*/,
mp */*b*/);
/* --- @mp_sub@ --- *
*
* Arguments: @mp *d@ = destination
/* --- @mp_sub@ --- *
*
* Arguments: @mp *d@ = destination
- * @
const
mp *a, *b@ = sources
+ * @mp *a, *b@ = sources
*
* Returns: Result, @b@ subtracted from @a@.
*/
*
* Returns: Result, @b@ subtracted from @a@.
*/
-extern mp *mp_sub(mp */*d*/,
const mp */*a*/, const
mp */*b*/);
+extern mp *mp_sub(mp */*d*/,
mp */*a*/,
mp */*b*/);
/* --- @mp_mul@ --- *
*
* Arguments: @mp *d@ = destination
/* --- @mp_mul@ --- *
*
* Arguments: @mp *d@ = destination
- * @
const
mp *a, *b@ = sources
+ * @mp *a, *b@ = sources
*
* Returns: Result, @a@ multiplied by @b@.
*/
*
* Returns: Result, @a@ multiplied by @b@.
*/
-extern mp *mp_mul(mp */*d*/,
const mp */*a*/, const
mp */*b*/);
+extern mp *mp_mul(mp */*d*/,
mp */*a*/,
mp */*b*/);
/* --- @mp_sqr@ --- *
*
* Arguments: @mp *d@ = destination
/* --- @mp_sqr@ --- *
*
* Arguments: @mp *d@ = destination
- * @
const
mp *a@ = source
+ * @mp *a@ = source
*
* Returns: Result, @a@ squared.
*/
*
* Returns: Result, @a@ squared.
*/
-extern mp *mp_sqr(mp */*d*/,
const
mp */*a*/);
+extern mp *mp_sqr(mp */*d*/, mp */*a*/);
/* --- @mp_div@ --- *
*
* Arguments: @mp **qq, **rr@ = destination, quotient and remainder
/* --- @mp_div@ --- *
*
* Arguments: @mp **qq, **rr@ = destination, quotient and remainder
- * @
const
mp *a, *b@ = sources
+ * @mp *a, *b@ = sources
*
* Use: Calculates the quotient and remainder when @a@ is divided by
* @b@.
*/
*
* Use: Calculates the quotient and remainder when @a@ is divided by
* @b@.
*/
-extern void mp_div(mp **/*qq*/, mp **/*rr*/,
- const mp */*a*/, const mp */*b*/);
+extern void mp_div(mp **/*qq*/, mp **/*rr*/, mp */*a*/, mp */*b*/);
/*----- More advanced algorithms ------------------------------------------*/
/*----- More advanced algorithms ------------------------------------------*/
@@
-634,9
+636,7
@@
extern void mp_div(mp **/*qq*/, mp **/*rr*/,
*
* Use: Calculates @gcd(a, b)@, and two numbers @x@ and @y@ such that
* @ax + by = gcd(a, b)@. This is useful for computing modular
*
* Use: Calculates @gcd(a, b)@, and two numbers @x@ and @y@ such that
* @ax + by = gcd(a, b)@. This is useful for computing modular
- * inverses. Neither @a@ nor @b@ may be zero. Note that,
- * unlike @mp_div@ for example, it is not possible to specify
- * explicit destinations -- new MPs are always allocated.
+ * inverses. Neither @a@ nor @b@ may be zero.
*/
extern void mp_gcd(mp **/*gcd*/, mp **/*xx*/, mp **/*yy*/,
*/
extern void mp_gcd(mp **/*gcd*/, mp **/*xx*/, mp **/*yy*/,
@@
-661,7
+661,7
@@
int mp_jacobi(mp */*a*/, mp */*n*/);
#include <mLib/testrig.h>
#include <mLib/testrig.h>
-#ifndef MPTEXT_H
+#ifndef
CATACOMB_
MPTEXT_H
# include "mptext.h"
#endif
# include "mptext.h"
#endif