How to detect a double's significant digits

Jeremy Bowers jerf at jerf.org
Fri May 6 12:27:11 EDT 2005


On Fri, 06 May 2005 08:27:03 +0200, Fredrik Lundh wrote:

> Jeremy Bowers wrote:
> 
>> > A step which will require him to tell the printing routine how many
>> > digits he wants printed.
>>
>> Not necessarily; consider the str() of a float in Python, especially
>> given the "significant digits" aspect (it may be ill-defined, but I can
>> think of several well-defined ways to mean that, where str() embodies
>> one of them). The easiest way to tell how long the number will be when
>> str prints it out is to simply ask it.
> 
> and what language is str() implemented in?

Who cares? It demonstrates the existence of a print routine that prints a
variable number of characters.

>> In C++, this may be harder, as your output software may insist on
>> rendering everything directly, with no way to reach in and tell what it
>> did. Imagine the standard IOStreams, without the ability to stream into
>> a string.
> 
> but you can stream into a string buffer, and you can use sprintf() from
> C++, so what's your point, besides stating that "if things were harder,
> they would be harder"?

Giving the original poster the benefit of the doubt, I assumed he was
dealing with some sort of screen library that would render something
without telling him the size, that didn't use streams at all. If that
library also implemented its own pretty print, string streams and
everything else don't help; you need *that* library's pretty print.



More information about the Python-list mailing list