Closed wmcbrine closed 8 years ago
Thank you!
I turned on warnings on avr-gcc, and got this warning:
C:\Users\Geek\AppData\Local\Temp\build1349657233616483660.tmp\J1772EvseController.cpp: In function 'long unsigned int ulong_sqrt(long unsigned int)': C:\Users\Geek\AppData\Local\Temp\build1349657233616483660.tmp\J1772EvseController.cpp:35:28: warning: left shift count >= width of type [enabled by default] unsigned long bit = 1 << 30;
the line should be
unsigned long bit = 1ul << 30;
but inexplicably changing 1 to 1ul adds 256 bytes of code!!!
so does
unsigned long bit = 0x40000000ul;
Tested (under x86) to give the same output with inputs up to 1000000, where it ran as much as 100 times faster -- yet (on Arduino) it even uses less compiled code. Taken from: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots
Also includes a small patch to save 12 more bytes (206 total).