Skip to content

rounding in Python 3 need not return a float #455

@cbm755

Description

@cbm755

This is based on a discussion in SymPy

I think round should return an mpf rather then a float. Consider:

>>> mp.dps = 64
>>> x = mpmath.mpf('0.66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666')

>>>  round(x, 48)      # is not going to give 48 digits
0.6666666666666666

>>> repr(_)            # its a float
'0.6666666666666666'

The current implementation of __round__ just converts to float and rounds there. I think we can do better---and are allowed to in Python 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementnew feature requests (or implementation)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions