hi,
can anyone help me to improve this function in order to be faster? right now it takes about 300micro sec
to execute and it it used every second.
I've found this page Code Review: Division of Integers by Constants
but i don't know how to port it on 32bit unsigned integer
In the code below the modulo is eating a lot of time
unsigned long M2(unsigned long z)
{
// multiplies UT hours expressed in seconds (0<=z<=86399)
// by 1.00273790935 without using float data type
// const unsigned long b=1002UL;
// const unsigned long c=7379UL;
// const unsigned long d=935UL;
// const unsigned long base=10000UL;
unsigned long dz=935UL*z;
unsigned long cz=7379UL*z;
unsigned long bz=1002UL*z;
unsigned long dz2=dz/10000UL;
cz=cz+dz2;
unsigned long cz2=cz/10000UL;
bz=bz+cz2;
unsigned long bz1=bz%10000UL;
unsigned long bz2=bz/10000UL;
unsigned long n=((bz2*100+bz1/100)+5)/10;
n=n-86400UL*(n/86400UL);
return n;
}
thank you