From ad6d26db88041fa9dd834a04fc5a8a714b6ef659 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Tue, 23 Apr 2024 12:08:20 +0200 Subject: [PATCH] fix build-CI --- .../fraction_exhaustive.ino | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/fraction_exhaustive/fraction_exhaustive.ino b/examples/fraction_exhaustive/fraction_exhaustive.ino index bf1422b..2cf2e13 100644 --- a/examples/fraction_exhaustive/fraction_exhaustive.ino +++ b/examples/fraction_exhaustive/fraction_exhaustive.ino @@ -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() { @@ -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();