On Sat, Aug 27, 2016 at 01:16:42PM +1200, Greg Ewing wrote:
> Steven D'Aprano wrote:
>
> >Obviously if I write 1.1K then I'm expecting a float.
>
> Why is it obvious that you're expecting a float and not
> a decimal in that case?
Because if you search the list archives you'll see that, in the short
term at least, I'm not in favour of changing the default floating point
type from binary floats to decimal floats *wink*
Also, I didn't say "binary float", I might have meant "decimal float"
:-)
But all joking aside, you are making a good point. Since the SI
units are all powers of ten, maybe this should be linked to decimal and
integer numbers rather than binary floats.
Let's look ahead to the day (Python 4? Python 5?) where there is a
built-in decimal floating point type with fixed precision. The existing
Decimal type will remain variable precision. Whatever suffixes we allow
now will limit our choices for this hypothetical "decimal128" (say)
type. So if we have:
123d
to mean 123 deci-units, or 123*10**-1, then we've just eliminated the
ability to make 123d a decimal. Now that's not necessarily a reason to
reject this proposal, but it does add a complication.
(And frankly, I'd rather get built-in fixed precision decimals than
syntax for scale factors. But that's another story.)
> >The SI units are all decimal, and I think if we support these, we should
> >insist that K == 1000, not 1024. For binary scale factors, there is the
> >IEC standard:
>
> Or perhaps allow the multiplier to be followed by
> 'b' or 'B' (bits/bytes/binary) to signal a binary scale
> factor.
Why sure! Let's ignore the perfectly good, well-known existing official
standard to invent our own standard that clashes with the de facto
standard use of "b" for bits and "B" for bytes!
*wink*
> >8M # remains a syntax error
> >0s8M # unambiguously an int with a scale factor of M = 10**6
>
> That looks ugly and hard to read to me.
>
> If we're to have that, I'm not sure 's' is the best character,
> since it suggest something to do with strings.
To be honest, I agree. Even though I suggested 0s as a prefix, I don't
actually like it. I much prefer the rule "any scale factor must follow
the last underscore of the number".
> >Proposal number two: don't make any changes to the syntax, but treat
> >these as *literally* numeric scale factors.
> >
> >k = kilo = 10**3
> >M = mega = 10**6
> >G = giga = 10**9
> >
> >int_value = 8*M
> >float_value = 8.0*M
> >fraction_value = Fraction(1, 8)*M
> >decimal_value = Decimal("1.2345")*M
>
> I like this!
I've started experimenting with this, and when I get time, I'll put it
on PyPI so that people can experiment with it too.
> >You can even scale by multiple factors:
> >
> >x = 8*M*K
>
> Which also offers a neat solution to the "floppy megabytes"
> problem:
>
> k = 1000
> kB = 1024
>
> floppy_size = 1.44*k*kB
Indeed, although I would write that as k*Ki.
--
Steve
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/