PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.64k stars 74 forks source link

Add *, /, and cbrt symbols(x, ÷, ∛) #75

Closed python128 closed 2 years ago

python128 commented 2 years ago

Also fixed a code block (rustfmt) in Contributing

I would also like to make an Average function to be used as such:

>> avg(12, 130, 12, 13, 14, 5, 10...) # Some other numbers 
Average = x # Where x is the average of the given numbers.

Where should I place the code for the above?

PaddiM8 commented 2 years ago

These symbols would be great to have. Unfortunately the evaluator doesn't understand them yet though, so they'll need to be added to kalk::lexer (in kalk/src) as well. For example, '*' => build(TokenKind::Star, "", span), would be '*' | '×' => build(TokenKind::Star, "", span),. Function aliases like the cbrt one are added in the next_identifier function (like with the sigmas there I believe). Then they all also need to be added to the is_valid_identifier function to make sure they're not parsed as variables. As for the powers... Hmm... They may be a bit more complicated.

Currently there are no functions with variadic parameters, but it may be possible without changing too much. Functions for kalker generally go in kalk::prelude::mod, but some special ones may be located directly in kalk::interpreter::eval_fn_call_expr. It could probably be placed here for now, and then I could see about making prelude functions a bit more flexible later on.