Skip to content

Commit

Permalink
fix build-CI
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Apr 23, 2024
1 parent 57c18b0 commit ad6d26d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions examples/fraction_exhaustive/fraction_exhaustive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
// AUTHOR: Rob Tillaart
// PURPOSE: exhaustive fraction testing
// URL: https://github.com/RobTillaart/Fraction
//
// Adjust accuracy if needed.

#include "fraction.h"

uint32_t start, stop;

float maxError = 0;
uint32_t lastTime = 0;

// step size to test, typical 100000
uint32_t N = 10000;

void setup()
{
Expand All @@ -22,28 +25,28 @@ void setup()

start = millis();

// test 0.00000 .. 1.00000
for (uint32_t n = 0; n <= 100000; n++)
for (uint32_t n = 0; n <= N; n++)
{
float g = n * 1e-5;
float g = n * (1.0 / N);
Fraction frac( g );
float f = frac.toFloat();
// test for relative error 1e-4 = 0.01%
// find the maxError so far.
float relError = abs(abs(f / g) - 1);
// float absError = abs(f - g);
if (relError > maxError)
// if (relError > maxError)
{
maxError = relError;
Serial.print(n);
Serial.print("\t");
Serial.print(frac.toString());
Serial.print("\t\t");
Serial.print(f, 6);
Serial.print("\t\t");
Serial.print(g, 6);
Serial.print("\t\t");
Serial.println(relError, 6);
Serial.print("\t");
Serial.print(f, 6);
Serial.print("\t");
Serial.print(100 * relError, 2); // as percentage
Serial.print("\t");
Serial.print(frac.toString());
Serial.println();
}
}
stop = millis();
Expand Down

0 comments on commit ad6d26d

Please sign in to comment.