Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Antoine Pitrou

Le 22/09/2017 à 19:15, Tim Peters a écrit :
> I've seen plenty of people on StackOverflow who (a) don't understand
> hex notation for integers; and/or (b) don't understand scientific
> notation for floats.  Nothing is self-evident about either; they both
> have to be learned at first.

Sure.  But, unless I'm mistaken, most people learn about the scientific
notation as teenagers (that was certainly my case at least, and that was
not from my parents AFAIR).  Which of them learn about hexadecimal float
notation at the same time?

> But if they see a rare:
> 
> x = float.fromhex("0x1.aaap-4")
> 
> they can Google for "python fromhex" and find the docs themselves at
> once.  The odd method name makes it highly "discoverable", and I think
> that's a feature for rare gimmicks with a small, specialized audience.

Basically agreed.  Moreover, "float.fromhex" spells it out, while the
literal syntax does not even make it obvious it's a floating-point
number at all.

Regards

Antoine.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Tim Peters
[Antoine Pitrou ]
> ...
> The main difference is familiarity.  "scientific" notation should be
> well-known and understood even by high school kids.  Who knows about
> hexadecimal notation for floats, apart from floating-point experts?

Here's an example:  you <0x0.2p0 wink>.  For people who understand
both hex and (decimal) scientific notation, learning what hex float
notation means is easy.


> So for someone reading code, the scientific notation poses no problem
> as they understand it intuitively (even if they may not grasp the
> difficulties of the underlying conversion to binary FP), while for
> hexadecimal float notation need they have to go out of their way to
> learn about it, parse the number slowly and try to make out what its
> value is.

I've seen plenty of people on StackOverflow who (a) don't understand
hex notation for integers; and/or (b) don't understand scientific
notation for floats.  Nothing is self-evident about either; they both
have to be learned at first.  Same for hex float notation.  Of course
it's true that many (not all) people do know about hex integers and/or
decimal scientific notation from prior (to Python) experience.

My objection is that we already have a way to use hex float notation,
and the _need_ for it is rare. If someone uninitiated sees a rare:

x = 0x1.aaap-4

they're going to ask on StackOverflow what the heck it's supposed to
mean.  But if they see a rare:

x = float.fromhex("0x1.aaap-4")

they can Google for "python fromhex" and find the docs themselves at
once.  The odd method name makes it highly "discoverable", and I think
that's a feature for rare gimmicks with a small, specialized audience.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Chris Barker
On Fri, Sep 22, 2017 at 8:37 AM, Guido van Rossum  wrote:

> On Thu, Sep 21, 2017 at 9:20 PM, Nick Coghlan  wrote:
>
>> >>> one_tenth = 0x1.0 / 0xA.0
>> >>> two_tenths = 0x2.0 / 0xA.0
>> >>> three_tenths = 0x3.0 / 0xA.0
>> >>> three_tenths == one_tenth + two_tenths
>> False
>>
>
> OMG Regardless of whether we introduce this feature, .hex() is the way to
> show what's going on here:
>
> >>> 0.1.hex()
> '0x1.ap-4'
> >>> 0.2.hex()
> '0x1.ap-3'
> >>> 0.3.hex()
> '0x1.3p-2'
> >>> (0.1+0.2).hex()
> '0x1.4p-2'
> >>>
>
> This shows so clearly that there's 1 bit difference!
>

Thanks! I really should add this example to the math.isclose() docs

.hex is mentioned in:

https://docs.python.org/3/tutorial/floatingpoint.html

but I don't see it used in a nice clear example like this.

-CHB









>
>
> --
> --Guido van Rossum (python.org/~guido )
>
> ___
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Guido van Rossum
On Thu, Sep 21, 2017 at 9:20 PM, Nick Coghlan  wrote:

> >>> one_tenth = 0x1.0 / 0xA.0
> >>> two_tenths = 0x2.0 / 0xA.0
> >>> three_tenths = 0x3.0 / 0xA.0
> >>> three_tenths == one_tenth + two_tenths
> False
>

OMG Regardless of whether we introduce this feature, .hex() is the way to
show what's going on here:

>>> 0.1.hex()
'0x1.ap-4'
>>> 0.2.hex()
'0x1.ap-3'
>>> 0.3.hex()
'0x1.3p-2'
>>> (0.1+0.2).hex()
'0x1.4p-2'
>>>

This shows so clearly that there's 1 bit difference!

-- 
--Guido van Rossum (python.org/~guido )
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread David Mertz
>
> Unrelated thought:  Users might be unsure if the exponent in a hexadecimal
> float is in decimal or in hex.


I was playing around with float.fromhex() for this thread, and the first
number I tried to spell used a hex exponent because that seemed like "the
obvious thing"... I figured it out quickly enough, but the actual spelling
feels less obvious to me.

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Rhodri James

On 22/09/17 03:57, David Mertz wrote:

I think you are missing the point I was assuming at. Having a binary/hex
float literal would tempt users to think "I know EXACTLY what number I'm
spelling this way"... where most users definitely don't in edge cases.


Quite.  What makes me -0 on this idea is that a lot of the initial 
enthusiasm on this list came from people saying exactly that.


--
Rhodri James *-* Kynesim Ltd
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Serhiy Storchaka

21.09.17 18:23, Victor Stinner пише:

My vote is now -1 on extending the Python syntax to add hexadecimal
floating literals.

While I was first in favor of extending the Python syntax, I changed
my mind. Float constants written in hexadecimal is a (very?) rare use
case, and there is already float.fromhex() available.

A new syntax is something more to learn when you learn Python. Is it
worth it? I don't think so. Very few people need to write hexadecimal
constants in their code.


Initially I was between -0 and +0. The cost of implementing this feature 
is not zero, but it looked harmless (while almost useless). But after 
reading the discussion (in particular the comments of proponents) I'm 
closer to -1.


This feature can be useful for very few people. And they already have 
float.fromhex(). Taking to account the nature of Python the arguments 
for literals are weaker than in case of statically compiled languages. 
For the rest of users it rather adds confusion and misunderstanding. And 
don't forgot about non-zero cost. You will be impressed by the number of 
places just in the CPython core and stdlib that should be updated for 
supporting a new type of literals.


___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


Re: [Python-ideas] Hexadecimal floating literals

2017-09-22 Thread Rob Cliffe



On 22/09/2017 02:32, Steven D'Aprano wrote:


Are there actually any Python implementations or builds which have
floats not equal to 64 bits? If not, perhaps it is time to make 64 bit
floats a language guarantee.



This will be unfortunate when Intel bring out a processor with 256-bit 
floats (or by "64 bit" do you mean "at least 64 bit"?).  Hm, is there an 
analog of Moore's law that says the number of floating-point bits 
doubles every X years? :-)


Unrelated thought:  Users might be unsure if the exponent in a 
hexadecimal float is in decimal or in hex.


Rob Cliffe
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/