leif wrote:
> Bob Smith wrote:
>> I'm puzzled by the description of this function which says that the base
>> may vary from 2..36 and -2..-36, but then goes on to describe the
>> allowed chars in the string for bases 37..62.
>>
>> Also, I see that you use the same odd rules as does GMP for different
>> bases.  That is,
>>
>> Bases        Allowed in String
>> ---------------------------------
>>   2..36        0..9a..z
>>  37..62        0..9A..Za..z
>>  -2..-36    0..9A..Z
>> -37..-62    unspecified
>>
>> Can anyone explain why not use one sequence for all bases (other than
>> that's the way GMP did it)?  If the latter explanation, does anyone know
>> why GMP did it that way?
> 
> I guess that's simply for historical reasons.  (And MPIR wanted to stay
> compatible with GMP.)
> 
> First, only bases up to 36 were supported, and using lower case letters
> was considered more convenient.
> 
> Later, bases up to 62 were added, and the developers didn't want to
> break backwards compatibility.
> 
> One could have used 0..9a..zA..Z for these, but then
> 
> ord(d1)<ord(d2) <=> val(d1)<val(d2)
> 
> would no longer hold (complicating the implementation), since for
> example ord('A')=65 < 97=ord('a'), but val('A')=36 > val('a')=10 in that
> case.


Oh, actually the answer is simpler.  The GMP documentation [1] says:

Function: int mpz_set_str (mpz_t rop, char *str, int base)

[...]

The base may vary from 2 to 62, or if base is 0, then the leading
characters are used: 0x and 0X for hexadecimal, 0b and 0B for binary, 0
for octal, or decimal otherwise.

For bases up to 36, case is ignored; upper-case and lower-case letters
have the same value. For bases 37 to 62, upper-case letter represent the
usual 10..35 while lower-case letter represent 36..61.


(The MPIR documentation of that function is identical.)

So *both* A..Z and a..z are allowed for bases up to 36, and the meaning
of a..z for bases >36 is straightforward, just as one would expect (I
think).

(The documentation of mpz_get_str() [2] is similar, except that of
course either lowercase or uppercase letters are used, or -- depending
on the base -- both at the same time, but then having different
significance.)


Btw., what documentation were you referring to?  The source code doesn't
contain what you cited either.



-leif

[1]
http://gmplib.org/manual/Assigning-Integers.html#index-mpz_005fset_005fstr-262

[2]
http://gmplib.org/manual/Converting-Integers.html#index-mpz_005fget_005fstr-280

-- 
() The ASCII Ribbon Campaign
/\ Help Cure HTML Email

-- 
You received this message because you are subscribed to the Google Groups 
"mpir-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mpir-devel?hl=en.

Reply via email to