replace float division with float multiplication in printFloat ==> 208 bytes less
- replaced an int by an uint8_t ==> 6 bytes less
void Print::printFloat(double number, uint8_t digits)
{
// Handle negative numbers
if (number < 0.0)
{
print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding *= 0.1;
// rounding /= 10.0; // <<<<<<<<<<<<<< more expensive than multiplication * 0.1
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
uint8_t toPrint = uint8_t (remainder); // <<<<<<<<<<<<<<<< for 1 digit a byte is enough...
print(toPrint, DEC);
remainder -= toPrint;
}
}
Sofar, in total 310 300 bytes less by looking carefully to the datatypes and operations in the print.cpp file
updated some numbers after a failing test.