2021-01-29 06:31:58 -05:00
|
|
|
|
// FILE: print_sci.ino
|
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
|
// PURPOSE: demo program SCI
|
|
|
|
|
|
2021-05-28 07:41:47 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
#include "printHelpers.h"
|
|
|
|
|
|
2021-05-28 07:41:47 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
void setup()
|
|
|
|
|
{
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
|
|
|
|
|
|
Serial.println(sizeof(float));
|
|
|
|
|
Serial.println(sizeof(double));
|
|
|
|
|
|
2022-10-01 07:17:26 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
double c = 2.99792458E8; // speed of light;
|
|
|
|
|
double m = 7.34767309E20; // mass of moon
|
|
|
|
|
double E = m * c * c;
|
|
|
|
|
|
|
|
|
|
Serial.println("\n Mass moon M = 7.34767309E+20");
|
|
|
|
|
Serial.println("Speed of light c = 2.99792458E+8");
|
|
|
|
|
Serial.println(" Print E = Mc^2 = 6.6037592413026551656653076E+21\n");
|
|
|
|
|
|
|
|
|
|
Serial.print(" normal print:\t");
|
|
|
|
|
Serial.println(E, 4);
|
|
|
|
|
Serial.println("Cannot handle floats / doubles > MAXLONG\n");
|
|
|
|
|
|
2022-10-01 07:17:26 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
#if defined(ARDUINO_ARCH_AVR)
|
2022-10-01 07:17:26 -04:00
|
|
|
|
char buffer[200];
|
2021-01-29 06:31:58 -05:00
|
|
|
|
Serial.print("dtostrf print:\t");
|
|
|
|
|
Serial.println(dtostrf(E, 4, 4, buffer));
|
|
|
|
|
Serial.println("Has no scientific notation\n");
|
|
|
|
|
|
|
|
|
|
Serial.print("dtostre print:\t");
|
|
|
|
|
Serial.println(dtostre(E, buffer, 4, 0 ));
|
|
|
|
|
Serial.print("dtostre print:\t");
|
|
|
|
|
Serial.println(dtostre(E, buffer, 16, 0 ));
|
|
|
|
|
Serial.println("Limited to 7 decimals\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-10-01 07:17:26 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
Serial.print(" sci print:\t");
|
|
|
|
|
Serial.println(sci(E, 4));
|
|
|
|
|
Serial.print(" sci print:\t");
|
|
|
|
|
Serial.println(sci(E, 16));
|
|
|
|
|
Serial.println("limited only by precision float\n");
|
|
|
|
|
|
2022-10-01 07:17:26 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
Serial.print(" eng print:\t");
|
|
|
|
|
Serial.println(eng(E, 4));
|
|
|
|
|
Serial.print(" eng print:\t");
|
|
|
|
|
Serial.println(eng(E, 16));
|
|
|
|
|
Serial.println("limited only by precision float\n");
|
|
|
|
|
|
2022-10-01 07:17:26 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
E /= 100; // more interesting effect
|
|
|
|
|
Serial.println("scieng() is not meant to use directly");
|
|
|
|
|
Serial.println("it works well up exponent multiple of 1..9");
|
|
|
|
|
Serial.println("some values for em have their esthetics too.\n");
|
|
|
|
|
for (int em = 1; em < 10; em++)
|
|
|
|
|
{
|
|
|
|
|
Serial.print(em);
|
|
|
|
|
Serial.print("\t");
|
|
|
|
|
Serial.println(scieng(E, 8, em));
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-01 07:17:26 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
Serial.println("\ndone...");
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 07:41:47 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
void loop()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-28 07:41:47 -04:00
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
// -- END OF FILE --
|
2021-12-24 07:26:40 -05:00
|
|
|
|
|