Skip to content

repr of mpmath.eps always displays the working precision 2.22045e-16~ #638

@WarrenWeckesser

Description

@WarrenWeckesser

This is with mpmath 1.2.1:

In [1]: import mpmath

In [2]: mpmath.mp.dps = 40

In [3]: mpmath.eps   # By default, ipython displays the repr of the input
Out[3]: <epsilon of working precision: 2.22045e-16~>

In [4]: str(mpmath.eps)
Out[4]: '2.29588740394978028900143854926219858949e-41'

Why does repr(mpmath.eps) show 2.22045e-16, while str(mpmath.eps) shows the expected value?

Presumably this is the result of the hard-coded argument dps=15 in the __repr__ method:
https://github.com/fredrik-johansson/mpmath/blob/fcc7e53362bc45fe372df4ac775e11678bd3f67d/mpmath/ctx_mp_python.py#L355-L356

Is that intentional? I suspect line 356 should be changed to something like

     return "<%s: %s~>" % (self.name, self.context.nstr(self, n=15)) 

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