Operators in Soplang
Operators are special symbols that perform operations on variables and values. Soplang provides a comprehensive set of operators for arithmetic, comparison, logical operations, and more.
On This Page
Arithmetic Operators
Arithmetic operators are used to perform mathematical operations between variables and values.
// Basic arithmetic operators door a = 10 door b = 3 // Addition door sum = a + b // 13 // Subtraction door difference = a - b // 7 // Multiplication door product = a * b // 30 // Division (returns float) door quotient = a / b // 3.3333... // Integer Division (floor division) door int_div = a // b // 3 // Modulus (remainder) door remainder = a % b // 1 // Exponentiation door power = a ** b // 1000 (10^3) // Negation door negative = -a // -10
Comparison Operators
Comparison operators are used to compare two values or expressions and return a boolean result (true or false).
// Comparison operators door a = 10 door b = 3 // Equal to door is_equal = a == b // false // Not equal to door not_equal = a != b // true // Greater than door greater = a > b // true // Less than door less = a < b // false // Greater than or equal to door greater_equal = a >= b // false // Less than or equal to door less_equal = a <= b // false
Logical Operators
Logical operators are used to combine conditional statements and evaluate boolean expressions.
// Logical operators door p = true door q = false // Logical AND door and_result = p && q // false // Logical OR door or_result = p || q // true // Logical NOT door not_result = !p // false // Alternative Somali keywords door iyo_result = p iyo q // Same as p && q (false) door ama_result = p ama q // Same as p || q (true) door ma_result = ma p // Same as !p (false)
Assignment Operators
Assignment operators are used to assign values to variables, often combining assignment with another operation.
// Basic assignment door x = 10 // Compound assignment operators // Addition assignment x += 5 // x = x + 5, now x is 15 // Subtraction assignment x -= 3 // x = x - 3, now x is 12 // Multiplication assignment x *= 2 // x = x * 2, now x is 24 // Division assignment x /= 4 // x = x / 4, now x is 6 // Integer division assignment x //= 2 // x = x // 2, now x is 3 // Modulus assignment x %= 2 // x = x % 2, now x is 1
Bitwise Operators
Bitwise operators perform operations on binary representations of integers at the bit level.
// Bitwise operators door a = 60 // 00111100 in binary door b = 13 // 00001101 in binary // Bitwise AND door and_result = a & b // 12 (00001100) // Bitwise OR door or_result = a | b // 61 (00111101) // Bitwise XOR (exclusive OR) door xor_result = a ^ b // 49 (00110001) // Bitwise NOT (complement) door not_result = ~a // -61 (11000011, in 2's complement) // Left shift door left_shift = a << 2 // 240 (11110000) // Right shift door right_shift = a >> 2 // 15 (00001111)