Git Product home page Git Product logo

Comments (3)

skirpichev avatar skirpichev commented on September 26, 2024

I don't sure it's an "incorrect". Same for gmplib:

$ cat a.c
#include <stdio.h>
#include <gmp.h>

int
main(int argc, char* argv[])
{
    int base = 42, x[2] = {35, 36};
    mpz_t n;
    mpz_init(n);
    for (int i = 0; i < 2; i++) {
        mpz_set_si(n, x[i]);
        fprintf(stdout, "%d: ", x[i]);
        mpz_out_str(stdout, base, n);
        fprintf(stdout, "\n");
    }
    mpz_clear(n);
    return 0;
}
$ cc a.c -lgmp && ./a.out 
35: Z
36: a

"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." (c) https://gmplib.org/manual/I_002fO-of-Integers

But maybe we should expand the digits docstring with this remark.

from gmpy.

sphynkx avatar sphynkx commented on September 26, 2024

Xmm.. turns out that you cannot apply the upper() operator to numbers.. Yes, it really would be reasonable to reflect this moment in the documentation, perhaps even in a separate section and especially case about the nomenclature of numbers. Because there is apparently no single and clear nomenclature for writing numbers with a non-standard base - there exist recommendations to exclude 'I' and 'O' (but for some reason not lowercase 'L') so as not to confuse them with similar numbers. However the gmplib docs doesn't specify that.
Anyway, there is still a problem in the code - lowercase letters are iterated from 'a' to 'f', while uppercase letters are in the full range.

from gmpy.

skirpichev avatar skirpichev commented on September 26, 2024

Xmm.. turns out that you cannot apply the upper() operator to numbers..

You can. But in general, this will be a different digit.

Yes, it really would be reasonable to reflect this moment in the documentation

On another hand, the gmpy2 is just a wrapper. So, in case of doubts - see the documentation of the GMP library (or MPFR/MPC).

However the gmplib docs doesn't specify that.

They do. That specification was quoted in the above post.

lowercase letters are iterated from 'a' to 'f'

No. That's only because you have used base=42.

>>> mpz(35).digits(62)
'Z'
>>> mpz(61).digits(62)
'z'

from gmpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.