Scientific RPN Calculator (with ATTINY85)
|
03-08-2018, 03:02 AM
(This post was last modified: 03-08-2018 03:14 AM by sa-penguin.)
Post: #21
|
|||
|
|||
RE: Scientific RPN Calculator (with ATTINY85)
That _exp_sin code is... cool.
I notice you use standard Arduino code for log(x) and atan(x) functions. I also noted temporary results held in multiple registers: SWAP, ROTUP, ROTDOWN and all the trig functions. I don't know if the code would be smaller or faster if you had one set of common registers. If you wanted to keep names to make the code easier to read, I'd suggest a union structure (lets you call the same variable by multiple names). I'd also suggest moving the square root code to the "sub programs" area, and calling it during the trig functions: double _sqrt(double f) { result = _exp_sin(0.5 * log(f), true); return result; } ... case SQRT: // SQRT x = _sqrt(x); break; ... double as = atan(x / _sqrt(1 - x * x)); ... else if (key == ASINH) x = log(x + _sqrt(tmp)); else if (key == ACOSH) x = log(x + _sqrt(tmp - 2)); That may make the code slightly smaller, but also improve readability. Just my $0.02 worth |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)