Skip to content

from_str: wrong parsing with underscores after decimal #377

@cbm755

Description

@cbm755

This works:

>>> mpmath.libmp.from_str('1_234.567891', 80)
(0, mpz(91095031707585398740483), -66, 77)
>>> mpmath.libmp.to_str(_, 24)
'1234.567891'

But underscores placed after the decimal point shift the decimal point incorrectly:

>>> mpmath.libmp.from_str('1_234.567_891', 80)
(0, mpz(1166016405857093103878183), -73, 80)
>>> mpmath.libmp.to_str(_, 24)
'123.4567891'

>>> mpmath.libmp.from_str('1_234.567_8_9_1', 80)
(0, mpz(746250499748539586482037), -79, 80)
>>> mpmath.libmp.to_str(_, 24)
'1.234567891'

The docs say "The literal syntax accepted is the same as for Python floats". But this is not so:

>>> 1_234.567_8_9_1
1234.567891

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions