Go Down

Topic: Serial.print() of a 64-bit DOUBLE (Read 12585 times) previous topic - next topic

robtillaart

From the test above some preliminary  conclusions:

printing 64 bits integers is not a daily job on an Arduino. 64 bit math is slow, but as these implementations show there is quite some performance to be gained at the cost of some footprint.

print6() is dedicated for base10 only, it has very good performance footprint ratio.

print9() is my favorite for all bases. The implementation is still reasonably straightforward while performance is very good. The footprint is substantially larger than print6()  (estimate factor 2+)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

MarkT

Quote

printing 64 bits integers is not a daily job on an Arduino. 64 bit math is slow, but as these implementations show there is quite some performance to be gained at the cost of some footprint.


Well on the Due there is 512kB of program memory and its 32 bit throughout.  The
only performance "gotcha" is the lack of divide hardware.  Any method of printing that
avoids / and % will likely win.  The fastest base 10 printing algorithm is test-subtraction
using a table of powers of ten - with that much flash available its not prohibitive to
store the table.

You need to avoid Serial library calls to get a true benchmark figure, in other
words time sprintf style conervsion, not printf style.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

sadr0b0t

Has this code ever been added to mainstream? I am on IDE 1.6.9 and Serial.println with "long long" is not going to compile.

robtillaart

@sadr0b0t

Created a pull request - https://github.com/arduino/Arduino/pull/6608 - with the code for long long ...


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

ard_newbie

#19
Aug 14, 2017, 09:24 am Last Edit: Aug 17, 2017, 09:01 am by ard_newbie
You can print uin64_t, int64_t and double this way:

Code: [Select]

uint64_t bignum0 = 0xFFFFFFFFFFFFFFllu;
uint64_t bignum1 = pow(2, 64) - 1;
int64_t bignum2 = - pow(2, 62);
double bignum3 = -1.123456789876543;

void setup() {
  Serial.begin(250000);
}

void loop() {
  printf(" bignum0 = 0x%llx\n", bignum0);
  printf(" bignum1 = %llu\n", bignum1);
  printf(" bignum2 = %lld\n", bignum2);
  Serial.print(" bignum3 = ");
  Serial.println(bignum3,15);
  delay(1000);
}





Go Up