how does the processor calculate power
does it use multiplication, so calculating 5^10 takes longer than 5^3?
or does it use a smarter algorithm?
It would be aefully silly to use multiplication for bitwise xor.... As for exponents I''m pretty sure most processors don''t have a built-in exponent function and I think would probably just use a loop with multiplying.
AP, however the exp() function yields in an exponent-type of expression, so ultimately leading to an a=b^c type of equation.
Personally I think that the CPU does use a spart algorithm, simply becaus how else would it calculate 1.234^5.6789
I don''t see how a looping algo will consider real numbers...
www.cppnow.com
Personally I think that the CPU does use a spart algorithm, simply becaus how else would it calculate 1.234^5.6789
I don''t see how a looping algo will consider real numbers...
www.cppnow.com
May 25, 2003 09:02 AM
quote:
As for exponents I''m pretty sure most processors don''t have a built-in exponent function and I think would probably just use a loop with multiplying.
The problem is that the exponent is a real number, so a loop is pretty much out of the question.. (as in pow(2,1.23))
May 25, 2003 09:12 AM
The x86 fpu has instructions to calculate 2**x-1 and log2(x) so pow it is probably implemented with them.
With an IEEE floating-point representation, one could simply multiply the power (square root is 1/2) into the 8 bit exponent of a 32-bit float for instance. And some other tricking, low-level operations would have to be done to the mantissa part of the float which is 23 bits long and in the range of: 1 <= mantissa < 2. Useful info is that the representation of an IEEE float implies the value is mantissa * 2^exponent --just like scientific notation but for base 2, which may or may not have some advantages. If the implication was only "mant^exponet," then one would only need to change the exponent, which would be extremely fastorz.
Is using sqrt really nothing more than dividing the power in the IEEE representation by 2?
So actually, sqrt is a very quick function, or am I being wrong here?
So actually, sqrt is a very quick function, or am I being wrong here?
Yes, SQRT is a fast function, like any CPU supported instructions.
Height Map Editor | Eternal Lands | Fast User Directory
Height Map Editor | Eternal Lands | Fast User Directory
quote:
Original post by Boops
Is using sqrt really nothing more than dividing the power in the IEEE representation by 2?
So actually, sqrt is a very quick function, or am I being wrong here?
sqrt divides the power by two, but the mantissa also gets modified. And no, it is not fast; at least not compared to most other operations. You should avoid them as much as you can in time-critical code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement