You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support full long double precision in __format__ (Trac #1783) #2376
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.
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.
Activity
aarchiba commentedon Aug 27, 2015
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.
aarchiba commentedon Sep 1, 2015
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.