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

[Feature Request] n-base functionality #85

Closed fennewald closed 2 years ago

fennewald commented 2 years ago

The addition of n-base functionality would be very helpful to kalker. I propose three changes: 1.) Literals of standard formats are understood. Namely, 0x, 0o and 0b. Examples of this functionality:

>> 0x10
10
>> 0b0101
5
>> 0o10
8

2.) Add the base predefined function, of the format base(n, m), which outputs the string representation of n in base m.

>> base(2, 2)
10

Note that if the output is not to the interactive prompt, it should be interpreted simply as n

>> base(2, 2) + base(2, 2)
4

Optionally, define the functions hex(n), oct(n), and bin(b) as shorthand for base(n, 16), base(n, 8), and base(n, b).

3.) Add a command line flag --base=n to define default base of output. e.g., kalker --base=16 would result in all outputs being default formatted as base 16.

fennewald commented 2 years ago

Just read the docs. I was running an ancient version. Similar features already exist. Closing!

PaddiM8 commented 2 years ago

I did indeed recently add support for things like 0x10 and 124₅, so it does work to some degree. However, I wouldn't call the current system complete. I actually think the other suggestions you made would be great to have. Although, I guess there's still the issue of how to deal with letters, since they may exist as variables. Maybe only literals should be allowed inside base.