[Python-ideas] Python Float Update

Andrew Barnert abarnert at yahoo.com
Tue Jun 2 00:30:08 CEST 2015


On Jun 1, 2015, at 08:12, Joonas Liik <liik.joonas at gmail.com> wrote:
> 
> I'm sorry..
> 
> what i meant was not a literal that results in a Decimal, what i meant was a special literal proxy object that usualyl acts like a float except you can ask for its original string form.

This is essentially what I was saying with new "literal constant" types. Swift is probably the most prominent language with this feature. http://nshipster.com/swift-literal-convertible/ is a good description of how it works. Many of the reasons Swift needed this don't apply in Python. For example, in Swift, it's how you can build a Set at compile time from an ArrayLiteral instead of building an Array and converting it to Set at compile time. Or how you can use 0 as a default value for a non-integer type without getting a TypeError or a runtime conversion. Or how you can build an Optional that acts like a real ADT but assign it nil instead of a special enumeration value. Or how you can decode UTF-8 source text to store in UTF-16 or UTF-32 or grapheme-cluster at compile time. And so on.

> 
> eg:
>  
> flit = 1.3
> flit*3 == float(flit)*3
> str(flit) == '1.3'
> 
> thus in cases where the intermediate float conversion loses precision you can get at the original string that the programmer actually typed in.
> 
> Decimal constructors are one case that woudl probably like to use the original string whenever possible to avoid conversion losses,
> but by no means are they the only ones.
> 
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list