Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Custom pow() Method using C++

#include <iostream>
#include <cmath>

using namespace std;

double fastPow(double a, double b) {
  union {
    double d;
    int x[2];
  } u = { a };
  u.x[1] = (int)(b * (u.x[1] - 1072632447) + 1072632447);
  u.x[0] = 0;
  return u.d;
}

double perc(double comp, double ref)
{
    return 100.0*(ref - comp)/comp;
}

int main()
{
    double a = 2.0E8;
    double b = 0.65;
    
    cout << fastPow(a,b) << endl; 
    cout << std::pow(a,b) << endl;
    cout << perc(fastPow(a,b),std::pow(a,b)) << endl;
   
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.