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

MRAB python at mrabarnett.plus.com
Wed Aug 31 13:07:14 EDT 2016


On 2016-08-31 17:19, Guido van Rossum wrote:
> On Wed, Aug 31, 2016 at 5:21 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> 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.
>
> I like it. So after all the drama we're just talking about adding an
> 'h' format code that's like 'g' but uses SI scale factors instead of
> exponents. I guess we need to debate what it should do if the value is
> way out of range of the SI scale system -- what's it going to do when
> I pass it 1e50? I propose that it should fall back to 'g' style then,
> but use "engineering" style where exponents are always a multiple of
> 3.)
>
>> 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".
>
> Not sure about this one.
>
Does the 'type' have to be a single character?

If not, how about 'hb' for binary scaling?



More information about the Python-ideas mailing list