c - Pow precision with unsigned longs -


so trying pow (x, y). x , y unsigned longs , result stored in unsigned long. result smaller 2^63 should able it. since returns floating point number inaccurate results big numbers. there anyway exact result without using external libraries bignum? know x*x y times, trying avoid because trying make program faster.

pow function returns double has precision issues , when cast long precision issue. far know if dont use library not possible accurate result using pow function alone.

you can @ exponentiation squaring , @ barak manos answer can try implement own pow function as

unsigned long long pow(unsigned long long x,unsigned int y) {     unsigned long long res = 1;     while (y > 0)     {         if (y & 1)             res *= x;         y >>= 1;         x *= x;     }     return res; } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -