soveran / clac

Command-line, stack-based calculator with postfix notation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add more functions in `math.h`

jasonmhite opened this issue · comments

So, wouldn't it make sense to simply implement all/most of the functions (and probably some of the constants) in math.h as primitives, since you're already using it? That should automatically give you most of the functions of a scientific calculator, plus the standard library implementations for those functions are very high quality. Having some of the standard unary operations like exp is also very convenient syntactically, because you can just do something like 5 3 exp * instead of 5 e 3 ^ * or 5 e 3 swap ^ * (I usually think in right to left order). At the very least more transcendental functions like atan and erf since you can't easily implement those in terms of other functions (and even if you could it's not a good idea because of numerical problems).

As another point regarding adding constants like e, pi etc., I feel like it'd make sense to just have those pre-loaded. It's not like anybody wants to customize the value of pi. Trying to add every obscure constant in existence isn't feasible, but the ones in math.h are already there and would be nice simply for numerical correctness.

I don't mind doing the legwork to add them, it's pretty easy. I already did exp, that was what motivated this. I'm interested in building a physical calculator using clac, hence the desire to make it a more complete scientific calculator.

This is relevant to issue #10.

I've implemented most of the functions over in my own fork if you want to take a look jasonmhite@0414af4 . I've added about 25 new words, mostly from math.h, but also deg2rad and rad2deg words to ease working with the trig functions.

Hey @jasonmhite, thanks a lot for your interest and your contributions! I really hope you've found clac useful for your use case. What kind of work do you do? Physics?

I will prepare a longer reply to this issue and post it later. I will reply to your other issue now.

I'm a nuclear engineering grad student, but I dabble in lots of different things and find clac convenient as a quick calculator. I too am a fan of dc and it seems like I first saw clac on a HN post, but I rediscovered it when I was searching for the source to dc because I noticed my version of dc didn't implement exp either, even though it's supposed to. Having exp / ln and trig functions is super important to me because I use them a lot.

PS I will also add documentation for the functions I've added if this is something you do want to include after we get it fixed up to your satisfaction.

@jasonmhite I'm sorry for the long delay, I have been extremely busy and I still am! But don't worry, we will get this done eventually :-)

No worries, I sympathize. Fortunately I'm not running any critical infrastructure on top of clac ;).

Thanks! First I was busy with the GDPR thing, now with some visits. I hope I'll have some time next week.

Almost over! Now it's only a matter of replying to customers who have questions. I'll go back to this issue tomorrow morning (finally).