Post Reply 
Scientific RPN Calculator (with ATTINY85)
03-15-2018, 12:19 PM
Post: #32
RE: Scientific RPN Calculator (with ATTINY85)
Great going! That's a lot of functionality cramed in.

I wonder if this saves any space:

Code:
      else if (key == SIN || key == COS || key == TAN) { // Trigonometric
        double si = _exp_sin(stack[0] / rad, false);
        double co = _sqrt(1 - si * si);
        if (key == SIN) stack[0] = si;
        else if (key == COS) stack[0] = co;
        else stack[0] = si / co;
      }
      else if (key == ASIN || key == ACOS) {
        double as = atan(stack[0] / _sqrt(1 - stack[0] * stack[0]));
        if (key == ASIN) stack[0] = as * rad;
        else stack[0] = (PI / 2 - as) * rad;
      } else if (key == ATAN)
        stack[0] = atan(stack[0]) * rad;
      else if (key == SINH || key == COSH || key == TANH) { // Hyperbolic
        double ep = _exp_sin(stack[0], true);
        double em = _exp_sin(-stack[0], true);
        if (key == SINH) stack[0] = (ep - em) / 2;
        else if (key == COSH) stack[0] = (ep + em) / 2;
        else stack[0] = (ep - em) / (ep + em);
      } else if (key == ASINH || key == ACOSH) {
        double tmp = stack[0] * stack[0] + 1;
        if (key == ASINH) stack[0] = log(stack[0] + _sqrt(tmp));
        else stack[0] = log(stack[0] + _sqrt(tmp - 2));
      } else if (key == ATANH)
        stack[0] = 0.5 * log((1 + stack[0]) / (1 - stack[0]));

Likewise, renumbering the functions (so they start from zero and are contiguous) and using an array of function pointers might help (it did on the 34S). This will depend on the processor.


This might also help:

Code:
      else if (key == SINH || key == COSH || key == TANH) { // Hyperbolic
        double ep = _exp_sin(stack[0], true);
        double em = _exp_sin(-stack[0], true);
        double s = (ep - em) / 2;
        double c = stack[0] = (ep + em) / 2;
        if (key == SINH) stack[0] = s;
        else if (key == COSH) stack[0] = c;
        else stack[0] = s / c;


Subject to typos and copy/paste errors.


Pauli
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Scientific RPN Calculator (with ATTINY85) - Paul Dale - 03-15-2018 12:19 PM



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