[Python-ideas] real numbers with SI scale factors: next steps

Nick Coghlan ncoghlan at gmail.com
Wed Aug 31 08:21:57 EDT 2016


On 31 August 2016 at 17:07, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Aug 31, 2016 at 2:08 PM, Ken Kundert
> <python-ideas at shalmirane.com> wrote:
>> > What's the mnemonic here? Why "r" for scale factor?
>>
>> My thinking was that r stands for real like f stands for float.
>> With the base 2 scale factors, b stands for binary.
>
> "Real" has historically often been a synonym for "float", and it
> doesn't really say that it'll be shown in engineering notation. But
> then, we currently have format codes 'e', 'f', and 'g', and I don't
> think there's much logic there beyond "exponential", "floating-point",
> and... "general format"? I think that's a back-formation, frankly, and
> 'g' was used simply because it comes nicely after 'e' and 'f'. (C's
> decision, not Python's, fwiw.) I'll stick with 'r' for now, but it
> could just as easily become 'h' to avoid confusion with %r for repr.

"h" would be a decent choice - it's not only a continuation of the
e/f/g pattern, it's also very commonly used as a command line flag for
"human-readable output" in system utilities that print numbers.

The existing "alternate form" marker in string formatting could be
used to request the use of the base 2 scaling prefixes rather than the
base 10 ones: "#h".

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list