Very interesting, Grahame! That confirms that using 64-bit floating point 
numbers for a calculator is not a good idea and std::float128_t is not 
implemented for the ESP32. 
I also had a look at CORDIC but I think that now I have the right solution. 
I had to make some changes but it seems that this Microsoft "rat thing" 
(rational package) is small and efficient enough to run on a ESP32. It must 
be used with caution as it is a minefield for memory leaks.
Here is the code for the square test (still learning how to use the lib):

#include <Arduino.h>
#include <iostream>
#include "ratpak.h"

#define RAT_RADIX 10
#define RAT_PRECISION 32

void setup()
{
  Serial.begin(115200);
  ChangeConstants(RAT_RADIX, RAT_PRECISION);
  //std::cout << esp_get_free_heap_size() << std::endl;
  PRAT a, b;
  PNUMBER an;
  std::string_view asw("1.0000001");
  an = StringToNumber(asw, RAT_RADIX, RAT_PRECISION);
  a = numtorat(an, RAT_RADIX);
  b = i32torat(2);
  for (int i = 0; i < 27; i++)
  {
    try
    {
      powrat(&a, b, RAT_RADIX, RAT_PRECISION);
      std::cout << RatToString(a, NumberFormat::Float, RAT_RADIX, 
RAT_PRECISION) << std::endl;
    }
    catch (uint32_t error)
    {
      std::cout << "Error: " << error << std::endl;
    }
  }
  destroyrat(a);
  destroyrat(b);
  destroynum(an);
}

And that's the output with the expected end result:
1.00000020000001
1.0000004000000600000040000001
1.000000800000280000056000007
1.000001600001200000560000182
1.000003200004960004960003596002
1.0000064000201600416640635376762
1.0000128000812803413770668026457
1.0000256003264027635374793520959
1.0000512013081822390029905871794
1.0001024052379384375785958510379
1.0002048209627096323852068743694
1.0004096838770460300710338611701
1.0008195355949711716087526439342
1.00163974282853376796974474111
1.0032821744136112638614741772487
1.006575121496103892166729172383
1.0131934752148963118187118095542
1.0265610182180387069187488015248
1.0538275241248563979233697036739
1.110552450603124793373875993221
1.2333267455406059342379630169179
1.5210948612657825396950367423048
2.3137295769691702316179381502588
5.3533445553419354350856785986392
28.658297928209144424271866810778
821.2980401419965396255701284542
674530.4707410845593826891780296

-- 
You received this message because you are subscribed to the Google Groups 
"neonixie-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion, visit 
https://groups.google.com/d/msgid/neonixie-l/1ad840d3-92d8-4a4d-9e7b-9268d10c3bcen%40googlegroups.com.

Reply via email to