GY-63_MS5611/libraries/FastTrig/examples/fastTrig_isincos/fastTrig_isincos.ino
2022-12-17 15:04:42 +01:00

137 lines
2.3 KiB
C++

// FILE: isincos.ino
// AUTHOR: Rob Tillaart
// DATE: 2022-12-09
// PURPOSE: R&D
#include "Arduino.h"
#include "FastTrig.h"
uint32_t start, stop;
volatile float x;
volatile int y;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(__FILE__);
delay(10);
start = micros();
for (uint32_t r = 0; r < 1000; r++)
{
x = sin(r);
}
stop = micros();
Serial.print("SIN: \t\t");
Serial.println(stop - start);
delay(10);
start = micros();
for (uint32_t r = 0; r < 1000; r++)
{
x = isin(r);
}
stop = micros();
Serial.print("ISIN: \t\t");
Serial.println(stop - start);
delay(10);
start = micros();
for (uint32_t r = 0; r < 1000; r++)
{
x = cos(r);
}
stop = micros();
Serial.print("COS: \t\t");
Serial.println(stop - start);
delay(10);
start = micros();
for (uint32_t r = 0; r < 1000; r++)
{
x = icos(r);
}
stop = micros();
Serial.print("ICOS: \t\t");
Serial.println(stop - start);
delay(10);
for (uint32_t r = 0; r <= 360; r++)
{
x = cos(r * PI / 180.0);
y = icos(r);
if (abs(x - y) >= 1)
{
Serial.print(r);
Serial.print('\t');
Serial.print(x);
Serial.print('\t');
Serial.print(float(y));
Serial.println();
}
}
Serial.println();
delay(100);
volatile float sum = 0;
start = micros();
for (uint32_t r = 0; r < 1000; r++)
{
sum += isin(r) + icos(r);
}
stop = micros();
Serial.print("ISIN + ICOS: \t");
Serial.println(stop - start);
Serial.println(sum);
delay(10);
sum = 0;
start = micros();
for (uint32_t r = 0; r < 1000; r++)
{
float p, q;
isincos(r, p, q);
sum += p + q;
}
stop = micros();
Serial.print("ISINCOS: \t");
Serial.println(stop - start);
Serial.println(sum);
delay(10);
for (uint32_t r = 0; r < 100; r++)
{
float p, q, s, t;
isincos(r*0.1, p, q);
s = isin(r*0.1);
t = icos(r*0.1);
if ((abs(p-s) > 0.0001) || (abs(q-t) > 0.0001))
{
Serial.print(r);
Serial.print("\t");
Serial.print(s, 6);
Serial.print("\t");
Serial.print(p, 6);
Serial.print("\t");
Serial.print(t, 6);
Serial.print("\t");
Serial.print(q, 6);
Serial.println();
}
}
delay(10);
Serial.println("\ndone...");
}
void loop()
{
}
// -- END OF FILE --