Quantcast
Channel: Cemetech
Viewing all articles
Browse latest Browse all 75829

Casio Prizm/FX Development & Programming :: RE: Useful Prizm Routines

$
0
0
Author: blue_bear_94
Posted: 27 Feb 2013 11:32:49 am (GMT -5)

Not sure if already done, but these routines re-implement the pow function without using math.h (since including it didn't work for me).

Code:

double exp(double x) {
   int i=2;
   double resC=1, resP=0;
   while (resC!=resP) {
      resP=resC;
      resC+=1./(i++);
   }
   return resC;
}

const double EULER=exp(1);

double powInt(double x, int n) {
   if (n<0) return 1./powInt(x,-n);
   double res=1;
   int i=0;
   for (i=0;i<n;i++) res*=x;
   return res;
}

double lnFor0To2(double x) {
   double y=x-1;
   int i=2;
   double resC=y, resP=0;
   while (resC!=resP) {
      resP=resC;
      resC+=(i%2?1:-1)*powInt(x,i)/i;
   }
   return resC;
}

double ln(double x) {
   if (0<x && x<=2) return lnFor0To2(x);
   else return 1+lnFor0To2(x/EULER);
}

double pow(double x, double y) {
   return exp(y*ln(x));
}

_________________
Do NOT click any links!


Viewing all articles
Browse latest Browse all 75829

Latest Images

Trending Articles



Latest Images