ninja2
Well-known member
how can I output a long double to many digits. For example my sketch below uses dtostrf, but the output is only accurate to about 10 digits, like this:
------ ------- -------
D2R:
_input: 0.017453292519943295769236907684886L
dtostrf: 0.017453292384743690490722656250000
------ end setup -------
heres the sketch:
------ ------- -------
D2R:
_input: 0.017453292519943295769236907684886L
dtostrf: 0.017453292384743690490722656250000
------ end setup -------
heres the sketch:
Code:
const char CJ_ID[] = "t3D2Rtest.a";
#define LED LED_BUILTIN
#include <Streaming.h>
//nst double D2R = DEG_TO_RAD; // can't use - missing "L" in wiring.h
const long double D2R = 0.017453292519943295769236907684886L;// degrees to radians, to 33 places
char valBuffer[50] = {0};
void setup() {
Serial.begin(115200);
while (!Serial && (millis() <= 4000)){ // wait for Serial to open, but only for 4 secs
digitalWriteFast(LED,!digitalReadFast(LED)); // toggle LED
delay(50);} // rapidly!
digitalWrite(LED, LOW); // then off
Serial << "### ##### " << CJ_ID << "########\n";
Serial << F(" * Serial open, millis: ") << millis() << '\n';
Serial << "\n------ ------- -------\n";
Serial << "D2R:" << '\n'; // degrees to radians
Serial << " input:\t 0.017453292519943295769236907684886L" << '\n'; // degrees to radians
dtostrf(D2R, 35, 33, valBuffer); // long double in, width, precision, buffer
Serial << "dtostrf:\t"; Serial.println(valBuffer);
Serial << "------ end setup -------" << '\n';
}
void loop() {}
Last edited: