Nice work Tom!
I have some functions prototyped some time ago. can be used as starting point but can still be optimized further.
divu24, divu12, divu3600, for clock math
uint32_t div24(uint32_t in)
{
return div3(in) >> 3;
}
uint32_t div12(uint32_t in)
{
return div3(in) >> 2;
}
uint32_t div86400(uint32_t in) // seconds to days
{
return ((in >> 1) + (in >>2) + (in>>7) + (in>>11) + (in>>12) - (in>>15)) >> 16;
}
uint32_t div3600(uint32_t in)
{
return div60(div60(in));
}
divu1000 - for millis/micros, millimeters to meters etc
some experimental code (to be optimized)
uint32_t div100(uint32_t in) // cm to meters
{
return div10(div10(in));
}
uint32_t div1000(uint32_t in)
{
return ((in>>2) + (in>>8) + ((in>>1) + (in>>5) + (in>>8) + (in>>11) + (in>>12) + (in >>14) + (in >> 15)) >> 8) >> 8 ;
}
div29 (for ultrasonic sensors) see - PING duration to cm division / 29 optimized - Libraries - Arduino Forum -
some gonio related experiments (to be optimized)
uint32_t divPI(uint32_t in)
{
uint32_t x = (in>>2) + (in>>4) + (in>>8) + (in>>9) - (in>>15) + (in >>17); // minus is correct
return x;
}
uint32_t mulPI(uint32_t in)
{
uint32_t x = (in<<1) + in + (in>>3) + (in>>6) + (in>>10);
return x;
}
uint32_t degrees2radians(uint32_t in)
{
uint32_t x = (in>>1) + (in>>5);
x += (( (in>>1) + (in>>2) - (in>>3) + (in >>6) ) >>5);
return x >> 5;
}
uint32_t radians2degrees(uint32_t in)
{
uint32_t x = (in << 5) + (in<<4) + (in<<3) + in + (in>>2) + (in>>5) + (in>>7) + (in>>8) + (in>>9) + (in >>10);
return x;
}
my div 13 code (not tested in detail)
uint32_t div13(uint32_t in)
{
// powers 4, 7,8,9,11,12,16, 19,20,21,23,24,28
uint32 t = in>>7 + in>>8 + in>>9 + in>>11 + in>>12 + in>>16;
t = t + t>>12;
return (in>>4) + t;
}