Do power functions in constant time?

When I use power functions like Math.Pow (double x, double y) in C # or math.h pow-function in C ++, are they executed in constant time?

The reason I ask is because I want to know if the "pre-calculated" function of the browser on the form (1-t) ^ n * p0 + ... + t ^ (n) * pN can work in linear time, which could be faster than the implementation of the De Casteljaus algorithm, taking control points and t as parameters.

+4
source share
1 answer

I think that these methods use iteration-based processing to get the result and stop only when the difference between the value of two iterations is below the given error constant.

There are iterative methods that converge very quickly to the result of a power operation ... so I think they are close to constant time.

There are many great explanations in this question: How is Math.Pow () implemented in the .NET Framework?

EDIT

I found a lot of good stuff to work with http://math.stackexchange.com .

This is very interesting as it explains the way of calculating exponentiation using human language:

Thoughts

I'm not a brilliant mathematician, but, as far as I can see, the time it takes does not depend much on the values ​​you choose, but on the number of exact numbers you want. I'm trying to say that it depends on the arguments, but there is a maximum.

Also, to support this theory, take a look at this algorithm (implemented by Sun): http://pastebin.com/LDjS5mAR . No cycles, only if. I think this is because the guys who implemented it chose the fixed accuracy that they wanted ... and then extended all the iterations needed to ensure accuracy.

For example, the cycle of an invariant number of iterations can be easily decomposed as follows:

for (int it = 0; it < 5; it++) a *= a; 

Same as:

 a *= a; a *= a; a *= a; a *= a; a *= a; 
+2
source

Source: https://habr.com/ru/post/1434925/


All Articles