Randomly choose negative or positive while excluding zero

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Randomly choose negative or positive while excluding zer

Post 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.
Shallow indentations.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests