Page 3 of 3

Re: Randomly choose negative or positive while excluding zer

Posted: Sun May 27, 2012 7:32 pm
by Boolsheet
timmeh42 wrote:And " ^ " isn't just a reference call to math.pow?
No, it gets translated into an opcode. The VM recognizes it and calls C's pow directly on both numbers.
timmeh42 wrote:And if not, why does math.pow use a slow method, when lua is supposedly a fast language?
Nobody said math.pow is slow, ^ is just faster. If you give Lua 'math.pow(x, y)' it has to do several steps to get to the actual exponentiation. The global variable 'math' could be anything, it has to look it up. If it is a table, 'pow' could hold any value and another lookup is necessary. Then, the function call does additional argument checks. The opcode for ^ does not have to do all this.