float / double support in Python?

Martijn Faassen m.faassen at vet.uu.nl
Thu Feb 13 16:35:50 EST 2003


Brandon Van Every <vanevery at 3dprogrammer.com> wrote:
> Martijn Faassen wrote:
>> Brandon Van Every <vanevery at 3dprogrammer.com> wrote:
>>>
>>> These aren't terribly tricky issues.  It's not like they have
>>> radically different encodings or purposes.
>>
>> You forget the potential loss of accuracy between conversions.
> 
> I forget no such thing.  It is simply not a tricky issue.

Dealing with C++'s machine type system *is* a tricky issue that people
worry about and create guidelines for. Perhaps you're so close to it
you don't see the problem anymore, but I'd rather not have to worry
about it. In Python I generally don't have to.

>> Anyway, here we have 6
>> things you should be thinking about when dealing with floats versus
>> doubles already!
> 
> You know, I know this drill.  It is not that hard of a drill.

As I said before somewhere, if you add up all these "not that hard of a
drill" you're going to end up with a more complicated system that
cuts in your development time. There's simply more stuff to worry
about, more code that clutters up your screen, more things that can
go wrong, more code to adjust if you decide to go the other route one day.
Python makes life simpler there. Since you really care about these issues,
perhaps you shouldn't use Python for handling these issues.

> It's
> something that the vast majority of non-numeric programmers can safely
> ignore. 

No, they cannot. If I'm going to write an API, do I use doubles or
floats? Signed or unsigned? Short or long? This matters, especially for
larger projects with a team of programmers. 

You could make your argument for assembler programming, actually. 
You could wonder why high level languages are necessary; they abstract
away from possibilities you have in assembly language, and you need those
features. People will tell you you can always descend into assembler
for these features, but you won't buy it. Really, all details of
assembler are pretty simple, after all.

In fact, that particular discussion *has* taken place extremely frequently
about assembler, when higher level programming languages were new.

So, you avoid programming in assembler if possible and favor C++. Is the only
reason portability or is something else involved as well? What?

> Numeric programmers, they're going to have to know the differences
> between IEEE 754, IEEE 854, and infinite floating point precision no matter
> what the language.

Yes.

>> Most Python programmers are not crossing the Python/C++ boundary that
>> often, let alone talking to 3d APIs like DirectX. You're complaining
>> as this is
>> *your* use case. If Python gave in to everybody's particular use case,
>> soon it'll become an awful mess.
> 
> If Python doesn't broaden its use cases, it doesn't gain mainstream
> acceptance and the language dies, beaten out by things such as Java and C#.

You don't know Python well enough to know what its use cases are. You cannot
therefore draw this conclusion based on your own use case. Besides, you
haven't even tried your use case with Python, so you can't even judge it
based on that, or perhaps I am missing something? Anyway, if not, then
you are not in any position to make this kind of judgement.

For some reason, Python has been steadily growing in the last decade
or more, not being beaten out by things like Java or C++ or C#. It's
grown so much so it's even drawn the interest from you. :) I don't think
we have anything to worry about. I have some idea -- I make my living writing
Python code.

>> Calling a 'floating
>> point number' a 'float' makes sense, calling them 'double' only makes
>> sense if you're coming from C.
> 
> No, it makes sense if you're coming from an engineering background and know
> the difference between single and double precision in the IEEE 754 and 854
> standards.  They're not C specific, they're machine HW standards.  An
> ultra-rational fix would be to introduce a "single" and a "double" keyword.

As an aside, you may not be aware, but Python doesn't do variable declaration,
so talking about keywords doesn't make much sense here.

Anyway, the words 'single' and 'double' mean so many different things 
in different contexts that it doesn't make much sense to me to use them
for numbers. Python is not optimized for people with a background in
IEEE 754 and 854 standards. It just calls floating point numbers 'float'.
They happen to be implemented by C doubles.

>> What is this 'real world' thingy you talk about?
> 
> My "real world" contains the IEEE 754 and 854 standards.

Okay, mine doesn't give them a lot of priority. My real world contains
a number of W3C standards. Perspectives differ. Your perspective is not
the only one, and not the most important one. In fact, I'd consider yours
currently a pretty unimportant one, as you haven't really tried Python
enough to form a very well thought out opinion. But perhaps I'm 
behind the time and you've played with things recently?

>> We already had masses of people complaining about this over the years
>> in this newsgroup, too. Endless amounts of debating! No, I think
>> you're one of the few ever to complain in my memory.. I don't think
>> that this shows that most of the "real world"s urgently need this.
> 
[snip remark not very useful in this discussion]

> I am getting sick of talking to Python developers
> about efficiency, conversion, and high-to-low-level multilanguage transition
> issues.  It's clear enough what the dominant Python culture is.

All right, sure. I'm however not yet sick of talking to Brandon whose
dominant culture is low level performance C++ 3d programming with 
a fairly tight vision. :)

> What I'm realizing is that although Python may be the right language for the
> novice user AI scripting tasks I originally envisioned, it not an ideal
> language for high level 3D graphics coding.

Yes, I agree it is likely not the right language for you. I think it can
work for many people who want to do high level 3D graphics coding, but
I think you may be a bit too tightly focused on some issues of debatable
importance to like it.

> I think I'll begin a search for something better and see what my options
> are.

As suggested before, you should look into Lisp.

>> I wonder what will happen when you discover that Python uses
>> indentation for block structure! ;)
> 
> I don't know why people assume that partial ignorance is categorical
> ignorance.

Some people do, other people may display a certain lack of humor at times.
Luckily we're not any of those people! :)

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?




More information about the Python-list mailing list