Topic: X to the Y power
Author: jss@lucid.com (Jerry Schwarz)
Date: Tue, 3 Mar 92 21:48:04 GMT Raw View
I have sympathy with the people who want more infix
operators whether they do numerical work or not.
I would have more sympathy with those who want an infix
power operation if they in turn exhibited some empathy
for the rest of us.
C is a language heavily biased towards numerical computation.
I know that people who do numerical computation don't like
C and don't see the bias, but consider this. There are two
application specific types for numerical computation,
"float" and "double". You can use infix operations on these types.
"double" is typically 64 bits, but there is typically no
64 bit integer type.
The reason for this bias is obvious, hardware is also
biased in this direction and C (along with almost all other
languages) followed. This was a reasonable decision.
C++ has finally put us all on a more or less even footing.
You can define your own types and use infix notation
on them. The only limitation is that you have to use the
original operators and precedences, which are not always right.
The ^ operator is usually rejected as a power operation
because it has the wrong precedence. "&" and "|" have
always had the wrong precedence those of use who use them
have learned to live with that.
Here are possible justifications for adding an infix
operator to C++.
a) It has a useful definition on integral types.
b) It has a precedence that is consistent with its
name and/or visual impact.
c) It is used in a variety of mathematical
(or non-mathematical) application areas in consistent
ways.
d) It has a useful definition on floating types.
People will give different weight to different potential
justifications based on their prejudices. For me (d) is
certainly the weakest possible justification.
-- Jerry Schwarz