[Python-Dev] Rich comparisons (original) (raw)
Michael Hudson mwh at python.net
Tue Mar 30 05:49:42 EST 2004
- Previous message: [Python-Dev] Rich comparisons
- Next message: [Python-Dev] funcdef grammar production
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Tim Peters" <tim.one at comcast.net> writes:
[>>> is Ed Loper, >> is me]
I'm also disturbed by the fact that cmp() has something different to say about their equality:
>>> cmp(float('nan'), float('nan')) 0 Well, yah. cmp() assumes a total ordering. If there just isn't one, what can we do? If we could recognize it was a NaN, my preference would be to raise an exception.
Well, we could sorta do this, by doing something like
if a > b: return 1 if a < b: return -1 if a == b: return 0 raise ValueError, 'can't compare NaNs'
which again goes back to depending on the C compiler.
I was told that GNU sort arranges to make NaNs look "less than" all non-NaN floats, which is a way to make a total ordering -- kinda.
Well, it's an answer. Not sure it's a good one.
I have at no point claimed that I have given Python 2.4 a coherent ieee 754 floating point story. Ya, but I keep telling people you claim that .
Oh! So it's your fault .
If someone (not me!) has the time and energy to do a 'proper job' (and I'd expect working out what that means to be the hard part), then you have my support and pre-emptive thanks. I don't believe it will happen until all the major C compilers support the (still optional!) 754 gimmicks in C99 -- or Python is rewritten in some other language that supports them. Before then, we'd need a small army of people expert in the intersection of their platform C and the 754 standard,
And Python's implementation!
to produce piles of #ifdef'ed platform-specific implementation code. That's doable, but unlikely.
T'would be easier in assembly (as would checking for overflow in int multiplication, but that's another story).
I could do 'it' in PPC assembly for MacOS X if I knew what 'it' was, but I'm not a hardcore numerics geek, I was just offended by float('nan') == 1 returning True.
Cheers, mwh
-- Haha! You had a really weak argument! -- Moshe Zadka, comp.lang.python
- Previous message: [Python-Dev] Rich comparisons
- Next message: [Python-Dev] funcdef grammar production
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]