Exponent 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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
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.
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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
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...