GY-63_MS5611/libraries/printHelpers/examples/sci_test/sci_test.ino
2021-12-24 13:26:40 +01:00

199 lines
2.9 KiB
C++

//
// FILE: sci_test.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test different values with sci function
#include "printHelpers.h"
uint32_t start, stop;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
test1();
test2();
test3();
test4();
test5();
test6();
Serial.println("\nDone...");
}
void loop()
{
}
void test1()
{
Serial.println();
Serial.println(__FUNCTION__);
double f = 1;
for (int i = 0; i < 40; i++)
{
f *= 10;
Serial.println(sci(f, 6));
}
Serial.println();
f = 1;
for (int i = 0; i < 50; i++)
{
f /= 10;
Serial.println(sci(f, 6));
}
Serial.println();
f = -1;
for (int i = 0; i < 40; i++)
{
f *= 10;
Serial.println(sci(f, 6));
}
Serial.println();
f = -1;
for (int i = 0; i < 50; i++)
{
f /= 10;
Serial.println(sci(f, 6));
}
Serial.println();
Serial.println();
}
void test2()
{
Serial.println();
Serial.println(__FUNCTION__);
double f = 1;
for (int i = 0; i < 40; i++)
{
f *= (PI * PI);
Serial.println(sci(f, 6));
}
Serial.println();
f = 1;
for (int i = 0; i < 50; i++)
{
f /= (PI * PI);
Serial.println(sci(f, 6));
}
Serial.println();
f = -1;
for (int i = 0; i < 40; i++)
{
f *= (PI * PI);
Serial.println(sci(f, 6));
}
Serial.println();
f = -1;
for (int i = 0; i < 50; i++)
{
f /= (PI * PI);
Serial.println(sci(f, 6));
}
Serial.println();
Serial.println();
}
void test3()
{
Serial.println();
Serial.println(__FUNCTION__);
double f = PI;
for (int digits = 0; digits < 15; digits++)
{
Serial.println(sci(f, digits));
}
Serial.println();
}
void test4()
{
Serial.println();
Serial.println(__FUNCTION__);
double f = PI;
for (int digits = 0; digits < 15; digits++)
{
sci(Serial, f, digits);
Serial.println();
}
Serial.println();
}
void test5()
{
Serial.println();
Serial.println(__FUNCTION__);
double f = 1.0 / 0.0;
Serial.println(sci(f, 6));
f = 0.0 / 0.0;
Serial.println(sci(f, 6));
f = -1.0 / 0.0;
Serial.println(sci(f, 6));
// TODO find a -inf
Serial.println(sci(tan(PI / 2), 6));
Serial.println();
}
void test6()
{
if (sizeof(double) >= 8)
{
Serial.println("DEC\tTIME\tVALUE");
for (int i = 0; i < 16; i++)
{
double f = PI * 1E307; // causes warning...
start = micros();
char * b = sci(f, i);
stop = micros();
Serial.print(i);
Serial.print('\t');
Serial.print(stop - start);
Serial.print('\t');
Serial.print(b);
Serial.println();
delay(10);
}
Serial.println();
}
// floats
Serial.println("DEC\tTIME\tVALUE");
for (int i = 0; i < 16; i++)
{
double f = PI * 1E38;
start = micros();
char * b = sci(f, i);
stop = micros();
Serial.print(i);
Serial.print('\t');
Serial.print(stop - start);
Serial.print('\t');
Serial.print(b);
Serial.println();
delay(10);
}
}
// -- END OF FILE --