projects
/
u
/
mdw
/
catacomb
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
09d00c6
)
Fix fencepost bugs in binary radix writing.
author
mdw
<mdw>
Tue, 15 Oct 2002 19:18:15 +0000
(19:18 +0000)
committer
mdw
<mdw>
Tue, 15 Oct 2002 19:18:15 +0000
(19:18 +0000)
mptext.c
patch
|
blob
|
blame
|
history
tests/mptext
patch
|
blob
|
blame
|
history
diff --git
a/mptext.c
b/mptext.c
index
565322d
..
40e1764
100644
(file)
--- a/
mptext.c
+++ b/
mptext.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mptext.c,v 1.1
4 2002/10/09 00:33:44
mdw Exp $
+ * $Id: mptext.c,v 1.1
5 2002/10/15 19:18:15
mdw Exp $
*
* Textual representation of multiprecision numbers
*
*
* Textual representation of multiprecision numbers
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
+ * Revision 1.15 2002/10/15 19:18:15 mdw
+ * Fix fencepost bugs in binary radix writing.
+ *
* Revision 1.14 2002/10/09 00:33:44 mdw
* Allow `0o' and `0b' prefixes for octal and binary (from Haskell)
*
* Revision 1.14 2002/10/09 00:33:44 mdw
* Allow `0o' and `0b' prefixes for octal and binary (from Haskell)
*
@@
-629,11
+632,12
@@
static int binary(mp *m, int bit, int radix, const mptext_ops *ops, void *p)
/* --- Work out where to start --- */
n = mp_bits(m);
/* --- Work out where to start --- */
n = mp_bits(m);
- n += bit - (n % bit);
+ if (n % bit)
+ n += bit - (n % bit);
b = n % MPW_BITS;
n /= MPW_BITS;
b = n % MPW_BITS;
n /= MPW_BITS;
-
- if (n > MP_LEN(m)) {
+
+ if (n >
=
MP_LEN(m)) {
n--;
b += MPW_BITS;
}
n--;
b += MPW_BITS;
}
@@
-704,6
+708,9
@@
int mp_write(mp *m, int radix, const mptext_ops *ops, void *p)
{
int rc;
{
int rc;
+ if (MP_EQ(m, MP_ZERO))
+ return (ops->put("0", 1, p));
+
/* --- Set various things up --- */
m = MP_COPY(m);
/* --- Set various things up --- */
m = MP_COPY(m);
diff --git
a/tests/mptext
b/tests/mptext
index
c6f7a8b
..
db6ed83
100644
(file)
--- a/
tests/mptext
+++ b/
tests/mptext
@@
-1,6
+1,6
@@
# Test vectors for MP textual I/O
#
# Test vectors for MP textual I/O
#
-# $Id: mptext,v 1.
9 2002/10/09 00:34:57
mdw Exp $
+# $Id: mptext,v 1.
10 2002/10/15 19:18:15
mdw Exp $
mptext-ascii {
# --- Perfectly valid things ---
mptext-ascii {
# --- Perfectly valid things ---
@@
-49,6
+49,7
@@
mptext-ascii {
# --- Word-boundary tests for binary-radix translation ---
# --- Word-boundary tests for binary-radix translation ---
+ 0 0 16 0;
8 1234567012 8 1234567012;
8 12345670123 8 12345670123;
8 123456701234 8 123456701234;
8 1234567012 8 1234567012;
8 12345670123 8 12345670123;
8 123456701234 8 123456701234;
@@
-57,6
+58,8
@@
mptext-ascii {
16 12345678 16 12345678;
16 123456789 16 123456789;
16 12345678 16 12345678;
16 123456789 16 123456789;
+ 10 -4009356060 16 -eef9eb1c;
+
# --- Bugs ---
16 84d192cd06ae59691897fa409da6198d5269325d
# --- Bugs ---
16 84d192cd06ae59691897fa409da6198d5269325d