#include <arithmetics.hpp>
This built-in CompilerPlugin of ALib Expressions primarily compiles unary and binary operators for permutations of types Boolean, Integer and Float.
By default, this plug-in is automatically created and inserted into each instance of class Compiler with the invocation of SetupDefaults.
General Notes:
All callback functions are defined compile-time invokable. This means that redundancies in expressions emerging from operations on constant numbers are optimized (pruned) by the compiler. For example, the two expressions: size > 81920 size > 8 * 1024
are resulting in an identical expression program and thus have identical evaluation performance.
0.0 and 1.1.1.true and false.true and false.'==' is aliased with '='.'&&') and '||' are aliased with operators '&' and '|'.Constant Identifiers:
The following constant identifiers provide variants for boolean values. No abbreviation is allowed.
| Return Type | Name | Description |
|---|---|---|
| Boolean | True | Returns constant true. |
| Boolean | False | Returns constant false. |
| Boolean | Yes | Returns constant true. |
| Boolean | No | Returns constant false. |
| Boolean | On | Returns constant true. |
| Boolean | Off | Returns constant false. |
Type Conversion Functions:
| Return Type | Name | Min. Abbreviation | Signature | Description |
|---|---|---|---|---|
| Boolean | Boolean | bool | <any> | Converts any type of boxed value by invoking box-function FIsTrue. |
| Integer | Integer | int | Boolean | Converts true to 1, false to 0. |
| Integer | Integer | int | Integer | Does nothing (identity function). |
| Integer | Integer | int | Float | Returns the integral part of a floating point number. |
| Float | Float | float | Boolean | Converts true to 1.0, false to 0.0. |
| Float | Float | float | Integer | Converts an integral value to floating point. |
| Float | Float | float | Float | Does nothing (identity function). |
Functions:
| Return Type | Name | Min. Abbreviation | Signature | Description |
|---|---|---|---|---|
| Integer | Length | len | <any array> | Returns the length of an array.
|
Unary Operators:
| Return Type | Operator | Argument Type | Description |
|---|---|---|---|
| Integer | + | Boolean | Converts the boolean value to integer. |
| Integer | + | Integer | Identity operator (has no effect). |
| Float | + | Float | Identity operator (has no effect). |
| Integer | - | Boolean | Converts the boolean value to integer and negates it. |
| Integer | - | Integer | Negates an integral value. |
| Float | - | Float | Negates a floating point value. |
| Boolean | ! | Boolean | Boolean not operator. |
| Boolean | ! | Integer | Returns the result of the comparison with 0. |
| Boolean | ! | Float | Returns the result of the comparison with 0.0. |
| Integer | ~ | Integer | Bitwise integral negation. |
Binary Operators:
| Return Type | Lhs Type | Operator | Rhs Type | Description |
|---|---|---|---|---|
| Integer | Boolean | * | Boolean | Multiplication with interpreting both boolean operands as integral value 0 or 1. |
| Integer | Boolean | * | Integer | Multiplication with interpreting the boolean operand as integral value 0 or 1. |
| Float | Boolean | * | Float | Multiplication with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | * | Boolean | Multiplication with interpreting the boolean operand as integral value 0 or 1. |
| Integer | Integer | * | Integer | Multiplication. |
| Float | Integer | * | Float | Multiplication. |
| Float | Float | * | Boolean | Multiplication with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Float | Float | * | Integer | Multiplication. |
| Float | Float | * | Float | Multiplication. |
| Integer | Boolean | / | Integer | Division with interpreting the boolean operand as integral value 0 or 1. |
| Float | Boolean | / | Float | Division with interpreting the boolean operand as integral value 0 or 1. |
| Integer | Integer | / | Integer | Division. |
| Float | Integer | / | Float | Division. |
| Float | Float | / | Integer | Division. |
| Float | Float | / | Float | Division. |
| Integer | Boolean | % | Integer | Modulo with interpreting the boolean operand as integral value 0 or 1. |
| Float | Boolean | % | Float | Modulo with interpreting the boolean operand as integral value 0 or 1. |
| Integer | Integer | % | Integer | Modulo. |
| Float | Integer | % | Float | Modulo. |
| Float | Float | % | Integer | Modulo. |
| Float | Float | % | Float | Modulo. |
| Integer | Boolean | + | Boolean | Addition with interpreting both boolean operands as integral value 0 or 1. |
| Integer | Boolean | + | Integer | Addition with interpreting the boolean operand as integral value 0 or 1. |
| Float | Boolean | + | Float | Addition with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | + | Boolean | Addition with interpreting the boolean operand as integral value 0 or 1. |
| Integer | Integer | + | Integer | Addition. |
| Float | Integer | + | Float | Addition. |
| Float | Float | + | Boolean | Addition with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Float | Float | + | Integer | Addition. |
| Float | Float | + | Float | Addition. |
| Integer | Boolean | - | Boolean | Subtraction with interpreting both boolean operands as integral value 0 or 1. |
| Integer | Boolean | - | Integer | Subtraction with interpreting the boolean operand as integral value 0 or 1. |
| Float | Boolean | - | Float | Subtraction with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | - | Boolean | Subtraction with interpreting the boolean operand as integral value 0 or 1. |
| Integer | Integer | - | Integer | Subtraction. |
| Float | Integer | - | Float | Subtraction. |
| Float | Float | - | Boolean | Subtraction with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Float | Float | - | Integer | Subtraction. |
| Float | Float | - | Float | Subtraction. |
| Integer | Boolean | << | Integer | Bitwise shift left with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | << | Boolean | Bitwise shift left with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | << | Integer | Bitwise shift left. |
| Integer | Boolean | >> | Integer | Bitwise shift right with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | >> | Boolean | Bitwise shift right with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Integer | Integer | >> | Integer | Bitwise shift right. |
| Boolean | Boolean | < | Boolean | Comparison operator with interpreting both boolean operands as integral value 0 or 1. |
| Boolean | Boolean | < | Integer | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Boolean | < | Float | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Integer | < | Boolean | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Integer | < | Integer | Comparison operator. |
| Boolean | Integer | < | Float | Comparison operator. |
| Boolean | Float | < | Boolean | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Float | < | Integer | Comparison operator. |
| Boolean | Float | < | Float | Comparison operator. |
| Boolean | Boolean | <= | Boolean | Comparison operator with interpreting both boolean operands as integral value 0 or 1. |
| Boolean | Boolean | <= | Integer | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Boolean | <= | Float | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Integer | <= | Boolean | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Integer | <= | Integer | Comparison operator. |
| Boolean | Integer | <= | Float | Comparison operator. |
| Boolean | Float | <= | Boolean | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Float | <= | Integer | Comparison operator. |
| Boolean | Float | <= | Float | Comparison operator. |
| Boolean | Boolean | > | Boolean | Comparison operator with interpreting both boolean operands as integral value 0 or 1. |
| Boolean | Boolean | > | Integer | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Boolean | > | Float | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Integer | > | Boolean | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Integer | > | Integer | Comparison operator. |
| Boolean | Integer | > | Float | Comparison operator. |
| Boolean | Float | > | Boolean | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Float | > | Integer | Comparison operator. |
| Boolean | Float | > | Float | Comparison operator. |
| Boolean | Boolean | >= | Boolean | Comparison operator with interpreting both boolean operands as integral value 0 or 1. |
| Boolean | Boolean | >= | Integer | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Boolean | >= | Float | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Integer | >= | Boolean | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Integer | >= | Integer | Comparison operator. |
| Boolean | Integer | >= | Float | Comparison operator. |
| Boolean | Float | >= | Boolean | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Float | >= | Integer | Comparison operator. |
| Boolean | Float | >= | Float | Comparison operator. |
| Boolean | Boolean | == | Boolean | Comparison operator with interpreting both boolean operands as integral value 0 or 1. |
| Boolean | Boolean | == | Integer | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Boolean | == | Float | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Integer | == | Boolean | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Integer | == | Integer | Comparison operator. |
| Boolean | Integer | == | Float | Comparison operator. |
| Boolean | Float | == | Boolean | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Float | == | Integer | Comparison operator. |
| Boolean | Float | == | Float | Comparison operator. |
| Boolean | Boolean | != | Boolean | Comparison operator with interpreting both boolean operands as integral value 0 or 1. |
| Boolean | Boolean | != | Integer | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Boolean | != | Float | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Integer | != | Boolean | Comparison operator with interpreting the boolean operand as integral value 0 or 1. |
| Boolean | Integer | != | Integer | Comparison operator. |
| Boolean | Integer | != | Float | Comparison operator. |
| Boolean | Float | != | Boolean | Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0. |
| Boolean | Float | != | Integer | Comparison operator. |
| Boolean | Float | != | Float | Comparison operator. |
| Integer | Integer | & | Integer | Bitwise boolean "and" operator. |
| Integer | Integer | | | Integer | Bitwise boolean "or" operator. |
| Integer | Integer | ^ | Integer | Bitwise boolean "xor" operator. |
| Boolean | Boolean | && | Boolean | Logical boolean "and" operator. |
| Boolean | Boolean | && | Integer | Logical boolean "and" operator. The integral operand is tested for a non-zero value. |
| Boolean | Boolean | && | Float | Logical boolean "and" operator. The floating point operand is tested for a non-zero value. |
| Boolean | Integer | && | Boolean | Logical boolean "and" operator. The integral operand is tested for a non-zero value. |
| Boolean | Integer | && | Integer | Logical boolean "and" operator. The integral operands are tested for a non-zero value. |
| Boolean | Integer | && | Float | Logical boolean "and" operator. The integral and floating point operands are tested for a non-zero value. |
| Boolean | Float | && | Boolean | Logical boolean "and" operator. The floating point operand is tested for a non-zero value. |
| Boolean | Float | && | Integer | Logical boolean "and" operator. The integral and floating point operands are tested for a non-zero value. |
| Boolean | Float | && | Float | Logical boolean "and" operator. The floating point operands are tested for a non-zero value. |
| Boolean | Boolean | || | Boolean | Logical boolean "or" operator. |
| Boolean | Boolean | || | Integer | Logical boolean "or" operator. The integral operand is tested for a non-zero value. |
| Boolean | Boolean | || | Float | Logical boolean "or" operator. The floating point operand is tested for a non-zero value. |
| Boolean | Integer | || | Boolean | Logical boolean "or" operator. The integral operand is tested for a non-zero value. |
| Boolean | Integer | || | Integer | Logical boolean "or" operator. The integral operands are tested for a non-zero value. |
| Boolean | Integer | || | Float | Logical boolean "or" operator. The integral and floating point operands are tested for a non-zero value. |
| Boolean | Float | || | Boolean | Logical boolean "or" operator. The floating point operand is tested for a non-zero value. |
| Boolean | Float | || | Integer | Logical boolean "or" operator. The integral and floating point operands are tested for a non-zero value. |
| Boolean | Float | || | Float | Logical boolean "or" operator. The floating point operands are tested for a non-zero value. |
Definition at line 232 of file arithmetics.hpp.
Public Methods | |
| ALIB_API | Arithmetics (Compiler &compiler) |
| virtual | ~Arithmetics () override |
| virtual ALIB_API bool | TryCompilation (CIFunction &ciFunction) override |
Public Methods inherited from Calculus | |
| Calculus (const NString &name, Compiler &compiler) | |
| virtual | ~Calculus () override |
| ALIB_API void | AddBinaryOpOptimizations (BinaryOpOptimizationsTableEntry *table, size_t length) |
| template<size_t TCapacity> | |
| void | AddBinaryOpOptimizations (BinaryOpOptimizationsTableEntry(&table)[TCapacity]) |
| void | AddOperator (const String &op, Type lhsType, Type rhsType, CallbackDecl callback, const char *dbgCallbackName, Type resultType, CTInvokable cti) |
| void | AddOperatorAlias (const String &alias, Type lhsType, Type rhsType, const String &op) |
| void | AddOperatorAliases (OperatorAliasTableEntry *table, size_t length) |
| template<size_t TCapacity> | |
| void | AddOperatorAliases (OperatorAliasTableEntry(&table)[TCapacity]) |
| ALIB_API void | AddOperators (OperatorTableEntry *table, size_t length) |
| template<size_t TCapacity> | |
| void | AddOperators (OperatorTableEntry(&table)[TCapacity]) |
| virtual ALIB_API bool | TryCompilation (CIAutoCast &autoCast) override |
| virtual ALIB_API bool | TryCompilation (CIBinaryOp &ciBinaryOp) override |
| virtual ALIB_API bool | TryCompilation (CIUnaryOp &ciUnaryOp) override |
Public Methods inherited from CompilerPlugin | |
| CompilerPlugin (const NString &name, Compiler &compiler) | |
| virtual | ~CompilerPlugin () |
| ALIB_API Arithmetics | ( | Compiler & | compiler | ) |
Constructor. Creates the hash maps.
| compiler | The compiler we will get attached to. |
|
inlineoverridevirtual |
|
overridevirtual |
Invokes parent's method. On failure, tries to compile function Length(array).
| [in,out] | ciFunction | The compilation information. |
true if an entry was found. false otherwise. Reimplemented from Calculus.