/* -*-c-*-
*
- * $Id: mptext.c,v 1.10 2001/06/16 13:22:39 mdw Exp $
+ * $Id: mptext.c,v 1.12 2002/01/13 19:51:18 mdw Exp $
*
* Textual representation of multiprecision numbers
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
+ * Revision 1.12 2002/01/13 19:51:18 mdw
+ * Extend the textual format to bases up to 62 by distinguishing case.
+ *
+ * Revision 1.11 2001/06/16 23:42:17 mdw
+ * Typesetting fixes.
+ *
* Revision 1.10 2001/06/16 13:22:39 mdw
* Added fast-track code for binary output bases, and tests.
*
*
* This is the number of bits in a @size_t@ object. Why?
*
- * To see this, let %$b = \mathit{MPW\_MAX} + 1$% and let %$Z$% be the
+ * To see this, let %$b = \textit{MPW\_MAX} + 1$% and let %$Z$% be the
* largest @size_t@ value. Then the largest possible @mp@ is %$M - 1$% where
* %$M = b^Z$%. Let %$r$% be a radix to read or write. Since the recursion
* squares the radix at each step, the highest number reached by the
/* --- If the radix is zero, look for leading zeros --- */
if (radix > 0) {
- assert(((void)"ascii radix must be <= 36", radix <= 36));
+ assert(((void)"ascii radix must be <= 62", radix <= 62));
rd = radix;
r = -1;
} else if (radix < 0) {
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
- ch = tolower(ch);
+ if (rd <= 36)
+ ch = tolower(ch);
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
- ch = tolower(ch);
+ if (rd <= 36)
+ ch = tolower(ch);
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
ch = x;
else if (x < 10)
ch = '0' + x;
- else
+ else if (x < 36) /* Ascii specific */
ch = 'a' + x - 10;
+ else
+ ch = 'A' + x - 36;
buf[--i] = ch;
if (z)
z--;
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
- ch = 'a' + x - 10;
+ ch = 'A' + x - 36;
*q++ = ch;
if (q >= buf + sizeof(buf)) {
if ((rc = ops->put(buf, sizeof(buf), p)) != 0)
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
- ch = 'a' + x - 10;
+ ch = 'A' + x - 36;
*q++ = ch;
rc = ops->put(buf, q - buf, p);
/* --- Check the radix for sensibleness --- */
if (radix > 0)
- assert(((void)"ascii radix must be <= 36", radix <= 36));
+ assert(((void)"ascii radix must be <= 62", radix <= 62));
else if (radix < 0)
assert(((void)"binary radix must fit in a byte", -radix < UCHAR_MAX));
else