PtcRunner.Lisp.Runtime.Math (PtcRunner v0.12.0)

Copy Markdown View Source

Arithmetic operations for PTC-Lisp runtime.

Provides basic math operations: addition, subtraction, multiplication, division, and utility functions like floor, ceil, round, etc.

Summary

Functions

Bitwise AND of all arguments (at least one, all integers).

Bitwise AND of the first argument with the complement of each subsequent one.

Clear bit n of x (set it to 0).

Flip bit n of x.

Bitwise complement (two's complement) of an integer.

Bitwise OR of all arguments (at least one, all integers).

Set bit n of x to 1.

Shift x left by n bits.

Arithmetic shift x right by n bits (sign-extending).

Return true if bit n of x is set.

Bitwise exclusive OR of all arguments (at least one, all integers).

Modulus with floored division (toward negative infinity).

Integer division (quotient), truncating toward zero.

Remainder with truncated division (toward zero).

Functions

abs(x)

add(args)

add(x, y)

bit_and(args)

Bitwise AND of all arguments (at least one, all integers).

bit_and_not(args)

Bitwise AND of the first argument with the complement of each subsequent one.

bit_clear(x, n)

Clear bit n of x (set it to 0).

bit_flip(x, n)

Flip bit n of x.

bit_not(x)

Bitwise complement (two's complement) of an integer.

bit_or(args)

Bitwise OR of all arguments (at least one, all integers).

bit_set(x, n)

Set bit n of x to 1.

bit_shift_left(x, n)

Shift x left by n bits.

bit_shift_right(x, n)

Arithmetic shift x right by n bits (sign-extending).

bit_test(x, n)

Return true if bit n of x is set.

bit_xor(args)

Bitwise exclusive OR of all arguments (at least one, all integers).

ceil(x)

compare(x, y)

dec(x)

divide(x, y)

double(x)

eq(x, y)

eq_variadic(args)

float(x)

floor(x)

gt(x, y)

gt_variadic(args)

gte(x, y)

gte_variadic(args)

inc(x)

int(x)

lt(x, y)

lt_variadic(args)

lte(x, y)

lte_variadic(args)

max(x, y)

min(x, y)

mod(x, y)

Modulus with floored division (toward negative infinity).

The result has the same sign as the divisor (y). Matches Clojure's mod function.

multiply(args)

multiply(x, y)

not_eq(x, y)

not_eq_variadic(args)

numeric_eq_variadic(args)

pow(x, y)

quot(x, y)

Integer division (quotient), truncating toward zero.

Matches Clojure's quot function.

Examples

iex> PtcRunner.Lisp.Runtime.Math.quot(7, 2)
3

iex> PtcRunner.Lisp.Runtime.Math.quot(-7, 2)
-3

iex> PtcRunner.Lisp.Runtime.Math.quot(7.5, 2)
3

remainder(x, y)

Remainder with truncated division (toward zero).

The result has the same sign as the dividend (x). Matches Clojure's rem function.

round(x)

sqrt(x)

subtract(list)

subtract(x, y)

trunc(x)