lutfenbot Help

/calc

The /calc command allows you to make calculations with units and functions.

The supported units and constants are provided by the dimAns Python library.

Parameters

t

the expression to calculate

Supports Units, Constants and Functions.

You can provide ? to view general calculator usage and expression syntax, ?units to get a list of all registered units, ?constants to get a list of all registered constants, and ?functions to get a list of all registered functions.

Language

The command has its own simple mini-language. In the definitions given below,

  • Expr is any expression,

  • Dimensional is a Quantity or Unit,

  • Ident is a Unit or Constant,

  • Number is a number,

  • Func is a function.

Expressions

Ident

Identifier (Unit or Constant usage)

Number

Integer or floating point number in decimal format, e.g. -1, 3.14

Func(Expr, ...)

Function call

(Expr)

Grouping

-Expr

Negation

+Expr

No operation

Expr ^ Expr

Exponentiation

Expr * Expr

Multiplication

Expr Ident

Identifier multiplication

Expr / Expr

Division

Expr mod Expr

Modulo

Expr + Expr

Addition

Expr - Expr

Subtraction

Expr -> Dimensional

Unit conversion

Expr -> (Dimensional, ...)

Sum unit conversion

Operation precedence

Order

Operations

1

Identifier usage, Number specification, Function usage, grouping.

2

Negation, no operation, exponentiation.

3

Multiplication, identifier multiplication, division, modulo.

4

Addition, subtraction.

5

Unit conversion, sum unit conversion.

Functions

Number-theoretic and representation functions

ceil(x)

Returns the smallest integer greater than or equal to x.

comb(n, k)

Returns the number of ways to choose k items from n items without repetition and without order.

copysign(x, y)

Returns x with the sign of y.

abs(x)

Returns the absolute value of x.

factorial(x)

Returns the factorial of x.

floor(x)

Returns the largest integer less than or equal to x.

mod(x, y)

Returns the remainder from the division of x by y, x mod y.

isfinite(x)

Returns True if x is a finite number, False otherwise.

isinf(x)

Returns True if x is positive or negative infinity, False otherwise.

isnan(x)

Returns True if x is NaN, False otherwise.

isqrt(x)

Returns the integer square root of x.

perm(n, k)

Returns the number of ways to choose k items from n items without repetition and with order.

trunc(x)

Returns the nearest integer to x towards 0.

Power and logarithmic functions

cbrt(x)

Returns the cube root of x.

exp(x)

Returns e raised to the power of x.

exp2(x)

Returns 2 raised to the power of x.

expm1(x)

Returns e raised to the power of x, minus 1.

log(x)

Returns the natural logarithm of x.

log(x, base)

Returns the logarithm of x with base base.

log1p(x)

Returns the natural logarithm of 1 plus x.

log2(x)

Returns the base 2 logarithm of x.

log10(x)

Returns the base 10 logarithm of x.

pow(x, y)

Returns x raised to the power of y, x ^ y.

sqrt(x)

Returns the square root of x.

Trigonometric functions

acos(x)

Returns the arc cosine (measured in radians) of x.

asin(x)

Returns the arc sine (measured in radians) of x.

atan(x)

Returns the arc tangent (measured in radians) of x.

atan2(y, x)

Returns the arc tangent of y / x (measured in radians) in the correct quadrant.

cos(x)

Returns the cosine of x (measured in radians).

dist(x, y)

Returns the Euclidean distance between x and y.

sin(x)

Returns the sine of x (measured in radians).

tan(x)

Returns the tangent of x (measured in radians).

Angular conversions

degrees(x)

Returns x radians expressed in degrees.

radians(x)

Returns x degrees expressed in radians.

Hyperbolic functions

acosh(x)

Returns the inverse hyperbolic cosine of x.

asinh(x)

Returns the inverse hyperbolic sine of x.

atanh(x)

Returns the inverse hyperbolic tangent of x.

cosh(x)

Returns the hyperbolic cosine of x.

sinh(x)

Returns the hyperbolic sine of x.

tanh(x)

Returns the hyperbolic tangent of x.

Special functions

erf(x)

Returns the error function at x.

erfc(x)

Returns the complementary error function at x.

gamma(x)

Returns the Gamma function at x.

lgamma(x)

Returns the natural logarithm of the absolute value of the Gamma function at x.

lutfen Calculator functions

dim(x)

Returns the dimensions of x.

unit(x)

Returns the unit of x.

val(x)

Returns the value of x.

uval(x)

Returns the underlying value of x.

Operator functions

add(x, y)

Returns x + y.

sub(x, y)

Returns x - y.

mul(x, y)

Returns x * y.

div(x, y)

Returns x / y.

neg(x)

Returns -x.

Last modified: 06 November 2024