Arithmetic / Logic: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
= Arithmetic / Logic = | = Arithmetic / Logic = | ||
The '''Arithmetic / Logic''' module provides essential mathematical operations and logical comparisons for the SCM programming language. This module includes: | |||
* '''Type checking''': Functions to verify data types (int?, number?, nil?) | |||
* '''Basic arithmetic''': Addition (+), subtraction (-), multiplication (*), and division (/) | |||
* '''Comparison operations''': All standard comparison operators (>, <, >=, <=, equal?) | |||
* '''Logical operations''': Boolean negation (!, not) and advanced equality checks | |||
* '''Mathematical functions''': Min/max operations and rounding functions (floor, ceil, round) | |||
These functions form the mathematical foundation for calculations and logical decision-making in SCM programs. | |||
← Back to [[Full SCM API documentation]] | |||
<span id="int"></span> | <span id="int"></span> | ||
== int? == | == int? == | ||
Revision as of 08:09, 27 August 2026
Arithmetic / Logic
The Arithmetic / Logic module provides essential mathematical operations and logical comparisons for the SCM programming language. This module includes:
- Type checking: Functions to verify data types (int?, number?, nil?)
- Basic arithmetic: Addition (+), subtraction (-), multiplication (*), and division (/)
- Comparison operations: All standard comparison operators (>, <, >=, <=, equal?)
- Logical operations: Boolean negation (!, not) and advanced equality checks
- Mathematical functions: Min/max operations and rounding functions (floor, ceil, round)
These functions form the mathematical foundation for calculations and logical decision-making in SCM programs.
← Back to Full SCM API documentation
int?
tells if the value is a integer
Allowed number of parameters: 1–1
Parameters
- value (
any): value
Returns
bool
number?
tells if the value is a number
Allowed number of parameters: 1–1
Parameters
- value (
any): value
Returns
bool
symbol?
tells if the value is a symbol
Allowed number of parameters: 1–1
Parameters
- value (
any): value
Returns
bool
+
adds two or more numbers
Allowed number of parameters: 0–10000
Parameters
- value... (
number): values to add (variadic)
Returns
number
sql_sum_reduce
adds two SQL SUM values while treating NULL as the empty aggregate identity
Allowed number of parameters: 2–2
Parameters
- left (
number|nil): partial sum - right (
number|nil): next value
Returns
number|nil
-
subtracts two or more numbers from the first one
Allowed number of parameters: 0–10000
Parameters
- value... (
number): values (variadic)
Returns
number
sql_add_numeric_literals
adds two SQL numeric literals using their exact decimal spellings
Allowed number of parameters: 2–2
Parameters
- a (
number): left literal - b (
number): right literal
Returns
number
sql_sub_numeric_literals
subtracts two SQL numeric literals using their exact decimal spellings
Allowed number of parameters: 2–2
Parameters
- a (
number): left literal - b (
number): right literal
Returns
number
*
multiplies two or more numbers
Allowed number of parameters: 0–10000
Parameters
- value... (
number): values (variadic)
Returns
number
/
divides two or more numbers from the first one
Allowed number of parameters: 0–10000
Parameters
- value... (
number): values (variadic)
Returns
number
mod
returns the remainder of integer division (modulo)
Allowed number of parameters: 2–2
Parameters
- a (
number): dividend - b (
number): divisor
Returns
number
<=
compares two numbers or strings; returns nil if either value is nil
Allowed number of parameters: 2–2
Parameters
- a (
any): first value - b (
any): second value
Returns
bool
<
compares two numbers or strings; returns nil if either value is nil
Allowed number of parameters: 2–2
Parameters
- a (
any): first value - b (
any): second value
Returns
bool
>
compares two numbers or strings; returns nil if either value is nil
Allowed number of parameters: 2–2
Parameters
- a (
any): first value - b (
any): second value
Returns
bool
>=
compares two numbers or strings; returns nil if either value is nil
Allowed number of parameters: 2–2
Parameters
- a (
any): first value - b (
any): second value
Returns
bool
equal?
compares two values of the same type, (equal? nil nil) is true
Allowed number of parameters: 2–2
Parameters
- a (
any): first value - b (
any): second value
Returns
bool
equal??
performs a SQL compliant sloppy equality check on primitive values (number, int, string, bool. nil), strings are compared case insensitive, (equal? nil nil) is nil
Allowed number of parameters: 2–2
Parameters
- a (
any): first value - b (
any): second value
Returns
bool
sql_not
negates a SQL predicate while preserving nil as UNKNOWN
Allowed number of parameters: 1–1
Parameters
- value (
any): SQL predicate value
Returns
bool|nil
equal_collate
performs SQL equality with a specified collation (e.g. *_ci case-insensitive, *_bin case-sensitive); returns nil if either arg is nil
Allowed number of parameters: 3–3
Parameters
- a (
any): left side - b (
any): right side - collation (
string): collation name
Returns
bool
notequal_collate
performs SQL inequality with a specified collation; returns nil if either arg is nil
Allowed number of parameters: 3–3
Parameters
- a (
any): left side - b (
any): right side - collation (
string): collation name
Returns
bool
!
negates the boolean value
Allowed number of parameters: 1–1
Parameters
- value (
bool): value
Returns
bool
not
negates the boolean value
Allowed number of parameters: 1–1
Parameters
- value (
bool): value
Returns
bool
nil?
returns true if value is nil
Allowed number of parameters: 1–1
Parameters
- value (
any): value
Returns
bool
min
returns the smallest value
Allowed number of parameters: 0–10000
Parameters
- value... (
number|string): value (variadic)
Returns
number|string
max
returns the highest value
Allowed number of parameters: 0–10000
Parameters
- value... (
number|string): value (variadic)
Returns
number|string
floor
rounds the number down
Allowed number of parameters: 1–1
Parameters
- value (
number): value
Returns
number
ceil
rounds the number up
Allowed number of parameters: 1–1
Parameters
- value (
number): value
Returns
number
round
rounds the number
Allowed number of parameters: 1–1
Parameters
- value (
number): value
Returns
number
sql_decimal_output
normalizes a DECIMAL-derived result to its declared output scale
Allowed number of parameters: 2–2
Parameters
- value (
number|nil): DECIMAL-derived value - scale (
int): declared decimal scale
Returns
number|nil
sql_abs
SQL ABS(): returns absolute value, NULL-safe
Allowed number of parameters: 1–1
Parameters
- value (
number): value
Returns
number
sqrt
returns the square root of a number
Allowed number of parameters: 1–1
Parameters
- value (
number): value
Returns
number
sql_rand
SQL RAND(): returns a random float in [0,1)
Allowed number of parameters: 0–0
Parameters
This function has no parameters.
Returns
number
parameterize_sql_select_literals
replaces safe literals in a top-level MySQL SELECT and returns normalized SQL, positional runtime bindings, and its stable shape hash
Allowed number of parameters: 1–1
Parameters
- query (
string):
Returns
list