zhengxyz123's calculator. A simple scientific calculator in 1,000 lines!
Type
python3 zcalc.py
in command line to enter interactive mode.
Or type
echo "1+2+3+4+5" | python3 zcalc.py
to calculate the expression immediately.
You can use the following command to change calculator setttings:
set <a_setting_name>=<an_integer_value>
Available settings are:
Name | Description | Default Value | Notes |
---|---|---|---|
precision | Precision in display | 15 | |
base | Numeric base in display (just for integers) | 10 | (1) |
enable_num2str | Whether or not to enable num2str | 1 | (2) |
Notes:
- Available options are
2
,8
,10
and16
. - Pass
0
to disable it. Learn more about num2str.
There are some undocumented settings, you can find them inside the source code. Changing the values of these settings is not recommended.
To get the current value of a setting, enter:
get <a_setting_name>
If you can't remember the names of the settings described in the table above, as well as the names of all keywords and functions described below, zcalc provides the ability to use the tab key to complete the syntax.
This feature is not available on platforms that do not have the readline
module installed.
zcalc only supports two types of numbers: int
and float
. Binary, octal and hexadecimal integers are also supported.
zcalc uses the same operator as Python, except:
In zcalc | In Python |
---|---|
! |
~ |
&& |
& |
|| |
| |
zcalc provides a lot of functions, they are:
- Number-theoretic and representation functions:
abs(x)
,ceil(x)
,comb(n, k)
,factorial(n)
,floor(x)
andperm(n, k=None)
- Power and logarithmic functions:
cbrt(x)
(Python 3.11 and above),exp(x)
,expm1(x)
,lg(x)
,ln(x)
,log(x, base=e)
andsqrt(x)
- Trigonometric functions:
acos(x)
,asin(x)
,atan(x)
,atan(y, x)
,cos(x)
,sin(x)
andtan(x)
- Angular conversion functions:
degrees(x)
andradians(x)
- Hyperbolic functions:
acosh(x)
,asinh(x)
,atanh(x)
,cosh(x)
,sinh(x)
andtanh(x)
- Special functions:
erf(x)
,erfc(x)
,gamma(x)
andlgamma(x)
zcalc also defines 3 constants that cannot be reassigned: e
, pi
and tau
.
The ans
variable stores the result of the last calculation.
zcalc uses a five-point template to compute numerical differentiation. If you want to calculate
diff sin(x)|x=pi
zcalc uses Adaptive Simpson′s Rule to compute numerical differentiation, if you want to calculte
int e**x|x=1~2
zcalc uses Newton's method to solve equations. If you want to solve
solve sin(x)-1/2|x=1
If you want to calculate
sum 2**n|x=1~100