Git Product home page Git Product logo

Comments (3)

skirpichev avatar skirpichev commented on September 26, 2024

Another example:

>>> int('  0xA',base=0)
10
>>> mpz('  0xA',base=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid digits

BTW, base=0 is incompatible with the int's base=10 default.

from gmpy.

casevh avatar casevh commented on September 26, 2024

Python and GMP handle embedded white space differently. They both ignore leading and trailing white space. But Python considers embedded white space an error while GMP ignores embedded white space.

The general rule is that gmpy2 should always return the same result as Python if no exception is raised by Python. Raising an exception when Python doesn't is a bug. Returning a "reasonable" value when Python raises an exception is acceptable (at least it is to me).

I think striping all white space is fine and matches the current behavior. But we won't match the Python exceptions for
embedded white space and I don't think it is worth changing GMP's behavior.

I also prefer the default of base=0. It is easier for converting strings that include the leading base indicators.

from gmpy.

skirpichev avatar skirpichev commented on September 26, 2024

The general rule is that gmpy2 should always return the same result as
Python if no exception is raised by Python. Raising an exception when
Python doesn't is a bug. Returning a "reasonable" value when Python raises
an exception is acceptable (at least it is to me).

Sure, that was the rule I kept in mind.

I think striping all white space is fine and matches the current behavior.

Probably, this does make sense for all constructors.

I also prefer the default of base=0. It is easier for converting strings
that include the leading base indicators.

My fault. That difference does matter only where Python raises exceptions (e.g. `int('0x10')).

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.