Post Reply 
Improve precision of float numbers
04-11-2019, 10:10 AM
Post: #1
Improve precision of float numbers
Hi all!

I like to build small RPN calculators (ScArY, SCOTT, ARC) with AVR microcontrollers (which are easy to program).

Unfortunately these microcontrollers support float numbers with 4 byte single precision (due IEEE-754) only. That means they support a precision of 6 to 7 decimal digits.

Now I would like to improve this precision to at least 9 decimal digits. The only idea I have is to define a new number format (struct) to separate mantissa and exponent:

Code:
struct real {
  long m;
  int8_t e;
};

But now I have to "reinvent" every mathematical operation like adding two numbers (the following code works, but is far from beeing efficient):

Code:
void realadd(real * res, real a, real b) {
  if (a.e >= b.e) {
    b.m /= _pow10(a.e-b.e);
    res->m = a.m + b.m;
    res->e = a.e;
  }
  else {
    a.m /= _pow10(b.e-a.e);
    res->m = a.m + b.m;
    res->e = b.e;
  }
}

Looking forward to transzendent functions or complex numbers I feel overstrained.

Do you have any other idea how to raise the precision with less effort?

Thanks for any idea.
deetee
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Improve precision of float numbers - deetee - 04-11-2019 10:10 AM



User(s) browsing this thread: 1 Guest(s)