arduino / ArduinoCore-API

Hardware independent layer of the Arduino cores defining the official API
https://www.arduino.cc/reference/en/
GNU Lesser General Public License v2.1
216 stars 120 forks source link

Serial.print(0ULL) gives empty output #178

Closed warmonkey closed 1 year ago

warmonkey commented 1 year ago

Test case: Serial.print(0ULL); Expected output: 0 Actual output: nothing

Quick fix:

// FAST IMPLEMENTATION FOR ULL
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
  //handle special case
  if (n64 == 0) {
    write('0');
    return 1;
  }
aentinger commented 1 year ago

Can you create a PR or at least a failing test case?

earlephilhower commented 1 year ago

Failing example from https://github.com/earlephilhower/arduino-pico/issues/1691

void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  uint64_t n = 123;
  uint64_t m = n;
  Serial.print("n - m = ");
  Serial.println(n - m);
  n++;
  Serial.print("n - m = ");
  Serial.println(n - m);
}
void loop() {}

Gives

n - m =
n - m = 1