soveran / clac

Command-line, stack-based calculator with postfix notation
BSD 2-Clause "Simplified" License
356 stars 30 forks source link

Suggestion: Sci-Calc #10

Closed cryogenicminer closed 6 years ago

cryogenicminer commented 6 years ago

Adding the basic functions for a scientific calculator would be great! Something along the lines of trig fn, logs. Anyways great setup for the calculator! As an engineer, these are functions I use on a regular basis.

Capaverde commented 6 years ago

I agree, those are very useful functions.

soveran commented 6 years ago

@cryogenicminer @Capaverde Thanks a lot for your input, I think I can add those functions. Given the fact that we can compose functions, what would be the minimal set of primitives we should hard code?

cryogenicminer commented 6 years ago

These, to me, are the basic functions: Sin, Cos, Tan, and Log.


Csc, Sec, and Cot can be defined in Words from standard Trig. If Log allows for different bases, then Ln can be defined in Words too. Otherwise, add Log (base 10) and Log (base e - Ln). The rest can be defined in Words like 'pi', 'e', and 'sqrt' etc.

Maybe we could work on offering a Words file for derived functions.

Anything I missed @Capaverde ? Edit: grammar & question

soveran commented 6 years ago

@cryogenicminer I just pushed the changes that include ln, log, sin, cos and tan. You can check the documentation.

About offering a words file for derived functions: it's an excellent idea! I created a wiki page for custom words, but maybe we should make it more prominent and/or easier to install.

Capaverde commented 6 years ago

@cryogenicminer I think having csc, sec, cot hardcoded might make it somewhat faster than processing sin 1 swap /, cos 1 swap /, tan 1 swap /, but I'm not sure if this is too important.

The arc functions, asin, acos, atan are also useful and I find use for them on a regular basis when converting between rectangular coordinates and polar coordinates, etc.

Other than that I can think of no other function very needed currently.

cryogenicminer commented 6 years ago

Ahh, I totally spaced on arcsin etc. Yes, those are important functions, way more important than csc, sec, and cot. I think you are right @Capaverde on hardcoding, but I think it won't be used nearly as much, and providing a 'word' to do the swap should make it seamless enough.

@soveran Thank you for the additions! Played around with it a bit, works great. Midterms just took place, so time has been scarce, but I appreciate your willingness to work on features!

soveran commented 6 years ago

The new functions are available in version 0.3.2. Thanks!

Capaverde commented 6 years ago

I've tried making a standalone similar to this and posted a gist, calling it stack.c. Maybe you'd like to check it out, though I've ended up abandoning it. Your code was a reference, but I implemented a switch statement using word hashes, and sone other things.

Capaverde commented 6 years ago

Here is the code in question:

https://gist.github.com/Capaverde/7136e02f450ffbc163968348820f41a3

soveran commented 6 years ago

@Capaverde Cool implementation! Thanks a lot for sharing it!