Skip to content

Converting exponent string with more than 1 "e"s to mpf does not throw an ValueError. #885

Description

@haydenwong7bm
>>> mpf('1e400e2')
mpf('9.9999999999999997e+399')
>>> mpf('1e400f2')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python312\Lib\site-packages\mpmath\ctx_mp_python.py", line 69, in __new__
    val = cls.mpf_convert_arg(val, prec, rounding, base)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\mpmath\ctx_mp_python.py", line 77, in mpf_convert_arg
    if isinstance(x, str): return from_str(x, prec, rounding, base)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\mpmath\libmp\libmpf.py", line 1292, in from_str
    man, exp = str_to_man_exp(x, base)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\site-packages\mpmath\libmp\libmpf.py", line 1239, in str_to_man_exp
    exp = int(parts[1])
          ^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '400f2'

mpf('1e400e2') should expected to throw a ValueError exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions