Skip to content

Support full long double precision in __format__ (Trac #1783) #2376

Open

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1783 on 2011-03-25 by @mwiebe, assigned to unknown.

For #2271, support was added for the format() function to numpy scalars. This support downcasts long doubles to doubles, so cannot print long doubles at their full precision. This should be fixed with custom formatting code in that case.

Activity

  1. aarchiba commented on Aug 27, 2015

    @aarchiba
    Contributor

    This would be desirable, since % cannot be adjusted to give full accuracy. And numpy does provide a version of printf that formats long doubles according to a printf format string. But getting this to work would require parsing a python format string and converting it to the appropriate printf format string, then filling in the rest correctly. Doable but non-trivial. Long double arrays can be printed in full precision using array2string and friends, so there is a slightly configurable way to get to ASCII without precision loss.

  2. aarchiba commented on Sep 1, 2015

    @aarchiba
    Contributor

    A good solution would basically require adapting python's format specification parsing and implementation; that is, most of the 1500 lines in https://github.com/python/cpython/blob/master/Python/formatter_unicode.c even if we don't worry about python2's string/unicode distinction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions