Calculate
Function reference for c-calculate
General
c-c <expression>
Shorthand syntax for c-calculate
.
c-c m [r | d]
Shorthand syntax for switching trigonometric modes.
deg, rad
Special modifiers that provide a shortcut for converting values between degrees and radians.
0b...
Prefix for writing numbers in binary notation.
0o...
Prefix for writing numbers in octal notation.
0x...
Prefix for writing numbers in hexadecimal notation.
a'n
Radix notation. This allows you to express a number n
in any base a
, from 1 to 64.
Operators
CalcBot supports the following operators, and evaluates them in the order listed:
++a, --a
Add or subtracts 1 from a
, and assigns the result to a
. Returns the value of a
after it was incremented (the value assigned to a
).
a++, a--
Add or subtracts 1 from a
, and assigns the result to a
. Returns the value of a
before it was incremented.
not n
Negates n
. If n
is a truthy value, false (0) is returned. Otherwise, true (1) is returned.
~n
Invert the bits of n
. The fractional part of n
will be truncated if there is any.
n!
Take the factorial of n
. For example, 6!
is equivalent to 6 * 5 * 4 * 3 * 2 * 1
.
a ^ b
Raise a
to the power of b
.
a * b
Multiply a
and b
.
a / b
Divide a
by b
.
a % b
Divide a
by b
and return the remainder of the result. This is also known as modulus division, or remainder division.
a + b
Add a
and b
.
a - b
Subtract b
from a
.
a << b
Shift all the bits in a
to the left b
times. For example, 1 << 3
is equal to 2 ^ 3
. After shiting by 3 bits, the resulting binary is 1000
, equivalent to 8
.
a >> b
Shift all the bits in a
to the right b
times. Bits at the end of the number will get discarded.
a == b
Returns true (1) if a
is equal to b
.
a != b
Returns true (1) if a
is not equal to b
.
a ~== b
Returns true (1) if a
is approximately equal to b
. The difference between them must be less than 1 * 10 ^ -6
. For complex numbers, this operator will compare the real and imaginary components separately.
This operator is intended to be used when comparing the results of certain mathematical operations that produce slightly imprecise results (like prime notation).
a ~!= b
Negates the behavior of the ~==
operator.
a > b
Returns true (1) if a
is greater than b
.
a < b
Returns true (1) if a
is less than b
.
a >= b
Returns true (1) if a
is greater than or equal to b
.
a <= b
Returns true (1) if a
is less than or equal to b
.
a & b
Compares the bits of a
and b
one by one. If both bits have a value of 1
, the corresponding bit in the new number will also be 1
.
a | b
Compares the bits of a
and b
one by one. If either bit has a value of 1
, the corresponding bit in the new number will also be 1
.
a && b
Returns true if both a
and b
are truthy values.
a || b
Returns true if either a
or b
are truthy values.
a = b
Assigns the value of b
to the symbol a
. If a
isn't a valid symbol, this operation will throw an error.
a ^= b, a *= b, a /= b, a %= b, a += b, a -= b, a <<= b, a >>= b, a &= b, a |= b, a &&= b, a ||= b
Compound assignment operators. For example, writing a ^= b
is a shortcut for writing a = a ^ b
; writing a += b
is a shortcut for a = a + b
, etc. If a
isn't a valid symbol, this operation will throw an error.
Control flow functions
bool(v)
Returns true (1) if v
is a truthy value. Otherwise, false (0) is returned.
if(cond, true_exp, false_exp = NaN)
Returns the value of true_exp
if cond
resolves to a truthy value. Otherwise, false_exp
is returned. If cond
resolves to a falsy value but false_exp
was not provided, NaN is returned.
loop(exp, start, end, step = 1, accum_exp = cur + acc)
Evaluates exp
where the special variable ind
represents the current index of the loop. ind
will be initially set to start
; then it will increment by step
until it reaches end
, at which point the loop will break and return the value of acc
.
If step
is not provided, it will be set to either 1 or -1 depending on the values of start
and end
.
accum_exp
is an expression that contains two special variables, cur
and acc
. cur
represents the current value of exp
, while acc
represents the combined values of all old values of cur
. Therefore, you can set accum_exp
to, for example, get the sum of a sequence exp
bounded by start
and end
. See the examples below for various ways you can utilize accum_exp
.
try(exp, error_exp)
Returns the value of exp
. If an error is generated while evaluating exp
, error_exp
will be returned instead.
Summation and product
sum(exp, variable, start, end)
Returns the summation of exp
, evaluated from when variable = start
to variable = end
. Both bounds are inclusive.
product(exp, variable, start, end)
Returns the product of exp
, evaluated from when variable = start
to variable = end
. Both bounds are inclusive.
Substitution
subst(exp, variable, value)
Substitutes value
for the variable
in the given expression. For example, subst(x^2+5x+6, x, 0)
substitutes 0
for x
in the expression x^2+5x+6
, giving 6
.
Trigonometric functions
sin(angle), cos(angle), tan(angle)
Returns the sine, cosine, or tangent of the angle.
csc(angle), sec(angle), cot(angle)
Reciprocal functions of sin(angle)
, cos(angle)
, and tan(angle)
respectively. For example, csc(angle) = 1 / sin(angle)
.
asin(value), acos(value), atan(value)
Inverse functions of sin(angle)
, cos(angle)
, and tan(angle)
respectively.
atan2(y, x)
Two-argument inverse tangent function.
acsc(value), asec(value), acot(value)
Inverse functions of csc(angle)
, sec(angle)
, and cot(angle)
respectively.
sinh(value), cosh(value), tanh(value)
Returns the hyperbolic sine, cosine, or tangent of the value.
csch(value), sech(value), coth(value)
Reciprocal functions of sinh(value)
, cosh(value)
, and tanh(value)
respectively. For example, csch(value) = 1 / sinh(value)
.
asinh(value), acosh(value), atanh(value)
Inverse functions of sinh(value)
, cosh(value)
, and tanh(value)
respectively.
acsch(value), asech(value), acoth(value)
Inverse functions of csch(angle)
, sech(angle)
, and coth(angle)
respectively.
Degree / radian conversion
dtr(degree), rad(degree)
Returns the given value converted to radians.
rtd(radian), deg(radian)
Returns the given value converted to degrees.
circle(value)
Returns the specified portion of one full revolution of a circle. For example, circle(0.5)
returns half of a full revolution. If the current trigonometric mode is degrees, this function returns value * 360
; otherwise, if it is radians, this function returns value * 2 * pi
.
Exponential / logarithmic functions
scientific(a, b)
Returns a * 10 ^ b
.
exp(x)
Exponential function with base e
. Returns e ^ x
.
log(x, y = 10)
Logarithmic function with base 10
by default.
ln(x)
Inverse function of exp(x)
. Equivalent to the logarithmic function with base e
, or log(x, e)
.
Root / power functions
hypot(a, b)
Returns the hypotenuse of a right triangle whose legs are a
and b
, formally the square root of the sum of squares of a
and b
, that is sqrt(a^2 + b^2)
.
sqrt(n)
Returns the square root of n
.
cbrt(n)
Returns the cube root of n
.
root(n, i)
Returns the i
th root of n
. For example, root(16, 2)
is equal to sqrt(16)
.
pow(n, p)
Returns n
raised to the p
power. This function is implicitly called when using the alternative syntax: n ^ p
.
Complex numbers
re(z)
Returns the real part of complex number z
.
im(z)
Returns the imaginary part of complex number z
.
arg(z)
Returns the argument of complex number z
.
conj(z)
Returns the complex conjugate of z
.
Sequences
fib(n)
Returns the n
th term of the Fibonacci sequence.
Statistics
ncr(n, k)
Combinations function. Returns the coefficient of the term x ^ k
in the polynomial expansion of the binomial (1 + x) ^ n
. This is also the number in row n
column k
of Pascal's triangle.
npr(n, r)
Permutations function. Computes the number of ways to obtain an ordered subset of r
elements from a set of n
elements.
Probability
normpdf(x, m = 0, s = 1)
Normal probability density function. Note that the returned values do not represent actual probabilities; you might be looking for normcdf.
normcdf(a, b, m = 0, s = 1)
Cumulative normal probability density function. Computes the probability of a normally distributed random variable, with mean m
and standard deviation s
, falling in the interval a
to b
.
geompdf(p, n)
Geometric probability function. Computes the probability that the first success of an event, with success probability p
, occurs on the n
th trial.
geomcdf(p, n)
Cumulative geometric probability function. Computes the probability that the first success of an event, with success probability p
, occurs on or before the n
th trial.
binompdf(n, p, x)
Binomial probability function. Computes the probability of exactly x
successes of an event, with success probability p
, occurring out of n
total trials.
binomcdf(n, p, x)
Cumulative binomial probability function. Computes the probability of x
or fewer success of an event, with success probability p
, occurring out of n
total trials.
Miscellaneous functions
erf(z)
Returns an approximation of the error function of z
.
erfc(z)
The complementary error function.
rand()
Returns a random number from 0 (inclusive) to 1 (non-inclusive).
Here is a custom function implementation that will generate random integers from a selected minimum and maximum, inclusively:
factorial(n)
Returns the factorial of n
. This function is implicitly called when using the alternative syntax: n!
gamma(n)
Returns the gamma function of n
using Lanczos's approximation.
abs(n)
Returns the absolute value of n
.
lerp(v1, v2, t)
Returns a value linearly interpolated fromv1
to v2
by a constant t
. For example, lerp(0, 10, 0.5)
returns the midpoint of 0
and 10
.
invlerp(v1, v2, v)
Calculates the linear parameter that produces the interpolant v
from v1
to v2
.
siground(n, d)
Returns n
rounded to d
significant digits.
round(n, s = 1)
Returns n
rounded to the nearest s
, integer by default.
ceil(n, s = 1)
Returns n
rounded up to the next s
, integer by default.
floor(n, s = 1)
Returns n
rounded down to the next s
, integer by default.
trunc(n, s = 1)
Returns n
rounded towards 0 to the next s
, integer by default. When n
is positive, this is equivalent to floor(n, s)
. When n
is negative, this is equivalent to ceil(n, s)
.
min(a, b)
Returns the lesser value of a
and b
.
max(a, b)
Returns the greater value of a
and b
.
gcf(a, b)
Computes the greatest common factor of a
and b
.
lcm(a, b)
Computes the least common multiple of a
and b
.
clamp(n, l, r)
Returns n
, clamped to the given range set by l
(left, negative) and r
(right, positive)
sign(n)
Returns the polarity of n
.
size(n)
Returns the amount of bits in the binary representation of n
. The fractional part of n
will be truncated if there is any.
Last updated