🎨
Xylo Docs
  • Introduction
  • Getting Started
    • Quickstart
  • Guides
    • Random Rotations
  • Syntax
    • Primitives
    • Functions
  • Control Flow
  • Builtin Functions
    • System
    • Math
    • Comparison
    • List
    • Randomness
    • Shape
    • Color
Powered by GitBook
On this page
  • Constants
  • Arithmetic Operators
  • Bitwise Operators
  • Conversion Functions
  • Trigonometric Functions
  • Hyperbolic Functions
  • Advanced Functions
Export as PDF
  1. Builtin Functions

Math

Constants

pi

The ratio of a circle's circumference to its diameter, approximately 3.14.

Can also be represented by the Unicode symbol π.

tau

Equal to 2Ï€ (approximately 6.28), representing the ratio of a circle's circumference to its radius.

Can also be represented by the Unicode symbol Ï„.

e

The base of natural logarithms, approximately 2.72.

Can also be represented by the Unicode symbol ℯ.

phi

The golden ratio, approximately 1.618.

Can also be represented by the Unicode symbol φ.

Arithmetic Operators

neg n

Changes the sign of n if possible. Accepts integer, float, and complex types.

Equivalent to the (-) unary operator.

Example:

three = neg -3
three = -(-3)

add x y

Adds x and y together if possible. Accepts integer, float, and complex types.

Equivalent to the (+) binary operator.

Example:

three = add 1 2
three = (+) 1 2
three = 1 + 2

sub x y

Subtracts x from y if possible. Accepts integer, float, and complex types.

Equivalent to the (-) binary operator.

Example:

three = sub 5 2
three = (-) 5 2
three = 5 - 2

mul x y

Multiplies x and y if possible. Accepts integer, float, and complex types.

Equivalent to the (*) binary operator.

Example:

six = mul 2 3
six = (*) 2 3
six = 2 * 3

div x y

Divides x by x if possible. Accepts integer, float, and complex types.

Equivalent to the (/) binary operator.

Example:

three = div 6 2
three = (/) 6 2
three = 6 / 2

mod x y

Returns the remainder of x divided by y if possible. Accepts integer, float, and complex types.

Equivalent to the (%) binary operator.

Example:

one = mod 5 2
one = (%) 5 2
one = 5 % 2

pow x y

Returns x to the power of y if possible. Accepts integer, float, and complex types.

Equivalent to the (**) binary operator.

Example:

nine = pow 3 2
nine = (**) 3 2
nine = 3 ** 2

Bitwise Operators

bitnot n

Inverts the bits of n. Accepts only integers.

Equivalent to the (~) unary operator.

Example:

one = bitnot -2
one = (~) -2
one = ~-2

bitand x y

Performs a bitwise AND operation on x and y. Accepts only integers.

Equivalent to the (&) binary operator.

Example:

one = bitand 5 3
one = (&) 5 3
one = 5 & 3

bitor x y

Performs a bitwise OR operation on x and y. Accepts only integers.

Equivalent to the (|) binary operator.

Example:

seven = bitor 5 3
seven = (|) 5 3
seven = 5 | 3

bitxor x y

Performs a bitwise XOR operation on x and y. Accepts only integers.

Equivalent to the (^) binary operator.

Example:

six = bitxor 5 3
six = (^) 5 3
six = 5 ^ 3

bitleft x y

Shifts the bits of x to the left by y positions. Accepts only integers.

Equivalent to the (<<) binary operator.

Example:

ten = bitleft 5 1
ten = (<<) 5 1
ten = 5 << 1

bitright x y

Shifts the bits of x to the right by y positions. Accepts only integers.

Equivalent to the (>>) binary operator.

Example:

two = bitright 5 1
two = (>>) 5 1
two = 5 >> 1

Conversion Functions

int n

Converts a float n to an integer.

Example:

three = int 3.5

float n

Converts an integer n to a float.

Example:

three_point_zero = float 3

complex re im

Returns a complex number with a real part re and an imaginary part im.

Example:

three_plus_five_i = complex 3 5

real n

Returns a float representing the real part of a complex number n.

Example:

three = real 3+5i

imag n

Returns a float representing the imaginary part of a complex number n.

Example:

five = imag 3+5i

deg_to_rad n

Converts n from degrees to radians. Accepts integer and float types.

Example:

half_of_pi = deg_to_rad 90

rad_to_deg n

Converts n from radians to degrees. Accepts integer and float types.

Example:

ninety = rad_to_deg (pi / 2)

Trigonometric Functions

sin n

Computes the sine of n radians. Accepts integer, float, and complex types.

Example:

zero = sin 0

cos n

Computes the cosine of n radians. Accepts integer, float, and complex types.

Example:

one = cos 0

tan n

Computes the tangent of n radians. Accepts integer, float, and complex types.

Example:

zero = tan 0

asin n

Computes the inverse sine of n . Accepts integer, float, and complex types.

Example:

zero = asin 0

acos n

Computes the inverse cosine of n. Accepts integer, float, and complex types.

Example:

zero = acos 1

atan n

Computes the inverse tangent of n . Accepts integer, float, and complex types.

Example:

zero = atan 0

atan2 y x

Computes the inverse tangent of y and x. Accepts integer and float types.

Example:

zero = atan2 0 1

Hyperbolic Functions

sinh n

Computes the hyperbolic sine of n radians. Accepts integer, float, and complex types.

Example:

zero = sinh 0

cosh n

Computes the hyperbolic cosine of n radians. Accepts integer, float, and complex types.

Example:

one = cosh 0

tanh n

Computes the hyperbolic tangent of n radians. Accepts integer, float, and complex types.

Example:

zero = tanh 0

asinh n

Computes the inverse hyperbolic sine of n radians. Accepts integer, float, and complex types.

Example:

zero = asinh 0

acosh n

Computes the inverse hyperbolic cosine of n radians. Accepts integer, float, and complex types.

Example:

zero = acosh 1

atanh n

Computes the inverse hyperbolic tangent of n radians. Accepts integer, float, and complex types.

Example:

zero = atanh 0

Advanced Functions

ln n

Computes the natural logarithm of n . Accepts integer, float, and complex types.

Example:

one = ln e

log10 n

Computes the logarithm base 10 of n . Accepts integer, float, and complex types.

Example:

two = log10 100

log base n

Computes the logarithm with base base of n . Accepts integer, float, and complex types for n and integer or float types for base.

Example:

four = log 3 81

abs n

Computes the absolute value of n . Accepts integer, float, and complex types.

Example:

one = abs -1

floor n

Returns the largest integer less than or equal to n. Accepts integer and float types.

Example:

three = floor 3.7

ceil n

Returns the smallest integer greater than or equal to n. Accepts integer and float types.

Example:

three = ceil 3.3

sqrt n

Computes the square root of n . Accepts integer, float, and complex types.

Example:

two = sqrt 4

cbrt n

Computes the cube root of n . Accepts integer, float, and complex types.

Example:

two = cbrt 8

fact n

Computes the factorial of n. Accepts integer and float types.

Example:

twenty_four = fact 4

fact2 n

Computes the double factorial of n. Accepts integer and float types.

Example:

eight = fact2 4

min x y

Returns the minimum of x and y. Accepts integer and float types.

Example:

three = min 3 5

max x y

Returns the maximum of x and y. Accepts integer and float types.

Example:

five = max 3 5
PreviousSystemNextComparison

Last updated 1 day ago