🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Exponent Operator

Started by
11 comments, last by WitchLord 19 years, 2 months ago
How about the ^ operator to act as the powerof. 2^2 = 4 2^5 = 32 etc.
Advertisement
Because the ^ operator is the bitwise xor operator.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Well, then how about ** as the exponent operator? [grin]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It would certainly be possible. But is it worth it?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Possible? Sure...

But when you consider the fact that the majority of the operators on built in types operate in constant time , a power operator, which not have a constant running time (except for some types), really doesn't make any sense.

Not to mention readability, the ^ operator is about the only one i would recognize as a power operator, ** would just be plain confusing. But if you're interoperating between C++ and AngleScript, ^ could become confusing very quickly. Something that won't happen with pow(x, y).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

I agree with you Washu.

The ^ operator is already taken, otherwise that would be the ideal one for the power-of operation. ** have been used by other languages, and can be used in AngelScript, but it might confuse C/C++ programmer (a large part of the AngelScript users). Also a power-of operator isn't used very often thus it's not too much to ask to make the programmer call a function instead.

The case where the power-of operator is used the most is for the base 2, in which case the << (shift left) operator works just as well, if not better.

I don't think I'll implement the power-of operator unless someone can come up with a really good reason for it.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote: Original post by WitchLord
I don't think I'll implement the power-of operator unless someone can come up with a really good reason for it.


Go ahead and implement arbitrary user-defined infix operators. [grin]

banana(x,y) pales in front of x banana y.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
That would be an option, except that it reserves keywords that might be used in other locations.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Oh yeah. I completely spaced that.

I didnt see the ^ in the list of operators, i must have just missed it.


And Washu, Multiplication is not constant time. It is repeated addition, and while it may be *fast* it is not constant time.

I brought this up because I have been converting a LUA script to AS and there is used a lot the ^ operator for powers.

Something like this: x pow 1456 is easier in my opinion to code than pow(x, 1456)

The only reason i proposed the operator was because in my initial skimming i did not see it currently being used.
Quote: Original post by Rain Dog
Something like this: x pow 1456 is easier in my opinion to code than pow(x, 1456)


My mention of arbitrary infix operators was a joke. They're not fun to implement. And pow(x,1456) will be more familiar to most than x pow 1456...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement