classNumericResult
final class NumericResult
Derives the result type of the arithmetic and bit operators.
Rule: MYSQL-NUMERIC-RESULT-001. The operands are classified by MYSQL-NUMERIC-CONTEXT-001. For +, - and * the result is DOUBLE when an operand is double precision, otherwise DECIMAL when an operand is exact decimal, otherwise a BIGINT that is UNSIGNED when an operand is; an integer subtraction with an unsigned operand is signed under the session mode NO_UNSIGNED_SUBTRACTION and unsigned otherwise; the profile does not hold the mode, so its type is the known choice of the signed and the unsigned BIGINT. / yields DOUBLE when an operand is double precision and DECIMAL otherwise. DIV yields a BIGINT, UNSIGNED when an operand is. % follows + but its integer result takes the sign of the dividend. The bit operators and ~ yield BIGINT UNSIGNED; from MySQL 8.0 they yield VARBINARY when their operands (for the shifts and ~, the shifted operand) are binary strings other than hexadecimal, bit and NULL literals. Unary minus keeps DECIMAL and DOUBLE, makes an integer a signed BIGINT, and makes an integer literal beyond the negated BIGINT range a DECIMAL. Terminates: no recursion. Source: https://dev.mysql.com/doc/refman/8.4/en/arithmetic-functions.html, https://dev.mysql.com/doc/refman/8.4/en/bit-functions.html, https://dev.mysql.com/doc/refman/8.4/en/sql-mode.html#sqlmode_no_unsigned_subtraction. Status: Implemented.
Methods§
public function binary(
ArithmeticOperator $operator,
Scalar $left,
ScalarFact $leftFact,
Scalar $right,
ScalarFact $rightFact,
GrammarRelease $release,
): TypeFactAnswers the result type of a binary operator over two operands and their facts.
Parameters
$operator | ArithmeticOperator | |
$left | Scalar | |
$leftFact | ScalarFact | |
$right | Scalar | |
$rightFact | ScalarFact | |
$release | GrammarRelease |
Returns
Test cases 3
Called from 1
Calls 13
- new Alternatives line 60
- method-call Alternatives::blocking() line 61
- method-call ArithmeticOperator::bitwise() line 65
- class-const ArithmeticOperator::ShiftLeft() line 66
- class-const ArithmeticOperator::ShiftRight() line 66
- method-call NumericResult::bits() line 68
- new NumericContext line 70
- method-call Alternatives::of() line 72
- method-call NumericResult::arithmetic() line 74
- method-call NumericContext::classify() line 74
- function-call
array_pushline 75 - method-call NumericResult::integer() line 75
- method-call Alternatives::known() line 79
public function arithmetic(
ArithmeticOperator $operator,
NumericClass $left,
NumericClass $right,
): ?TypeDescriptorAnswers the result type of an arithmetic operator over two classes, or null when it depends on NO_UNSIGNED_SUBTRACTION.
Parameters
$operator | ArithmeticOperator | |
$left | NumericClass | |
$right | NumericClass |
Returns
Test cases 1
Called from 1
Calls 12
- function-call
in_arrayline 88 - class-const NumericClass::Double() line 88
- class-const ArithmeticOperator::IntegerDivide() line 89
- method-call NumericResult::integer() line 89
- class-const NumericClass::Unsigned() line 89
- new Floating line 89
- class-const FloatingKind::Double() line 89
- class-const ArithmeticOperator::Divide() line 94
- class-const NumericClass::Decimal() line 94
- new Decimal line 95
- class-const ArithmeticOperator::Modulo() line 97
- class-const ArithmeticOperator::Minus() line 102
public function bits(
list<array{Scalar, ScalarFact}> $operands,
GrammarRelease $release,
): TypeFactAnswers the result type of a bit operator over the operands that decide between integer and binary string arithmetic.
Parameters
$operands | list<array{Scalar, ScalarFact}> | |
$release | GrammarRelease |
Returns
Test cases 1
Called from 2
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::binary() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:68
- method-call SqlSemantics\Platform\MySql\Statement\Expression\Operator\Unary::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Operator/Unary.php:62
Calls 6
- class-const GrammarRelease::MySql5651() line 112
- class-const GrammarRelease::MySql5744() line 112
- new Known line 113
- method-call NumericResult::integer() line 113
- new Binary line 124
- class-const BinaryKind::VarBinary() line 124
public function negation(Scalar $operand, ScalarFact $fact): TypeFactAnswers the result type of unary minus over an operand and its facts.
Parameters
$operand | Scalar | |
$fact | ScalarFact |
Returns
Test cases 1
Called from 1
Calls 15
- new Alternatives line 132
- method-call Alternatives::blocking() line 133
- method-call Alternatives::of() line 138
- method-call NumericContext::classify() line 139
- new NumericContext line 139
- class-const NumericClass::Signed() line 140
- class-const NumericClass::Unsigned() line 140
- method-call NumericResult::beyond() line 140
- new Decimal line 140
- method-call NumericResult::integer() line 140
- class-const NumericClass::Decimal() line 141
- class-const NumericClass::Double() line 142
- new Floating line 142
- class-const FloatingKind::Double() line 142
- method-call Alternatives::known() line 146
public function beyond(Scalar $operand): boolTells whether an operand is an integer literal whose negation lies below the BIGINT range.
Parameters
$operand | Scalar |
Returns
boolTest cases 1
Called from 1
public function integer(bool $unsigned): IntegralAnswers the BIGINT type, unsigned or not.
Parameters
$unsigned | bool |
Returns
Test cases 1
Called from 8
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::binary() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:75
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::arithmetic() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:89
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::arithmetic() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:92
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::arithmetic() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:98
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::arithmetic() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:102
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::bits() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:113
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::bits() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:124
- method-call SqlSemantics\Platform\MySql\Rules\Expression\NumericResult::negation() packages/sql-semantics-mysql/src/Rules/Expression/NumericResult.php:140
Calls 3
- new Integral line 170
- class-const IntegralKind::BigInt() line 170
- class-const NumericModifier::Unsigned() line 170
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 8
NumericResultTest::testArithmeticFollowsTheOperandClassescallsNumericResultTest::testBeyondComparesWithTheNegatedRangecallsNumericResultTest::testBinaryMakesABitOperationOfBinaryStringsABinaryStringFromMySql80callsNumericResultTest::testBinaryMakesAnUnsignedSubtractionTheChoiceTheSessionModeDecidescallsNumericResultTest::testBinaryTypesASumOfAnIntegerAndAStringcallsNumericResultTest::testBitsIgnoreAHexadecimalLiteralcallsNumericResultTest::testIntegerIsABigintcallsNumericResultTest::testNegationMakesALiteralBeyondTheRangeADecimalcalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\MySql\Statement\Expression\Operator\Arithmetic::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Operator/Arithmetic.php:68
- new SqlSemantics\Platform\MySql\Statement\Expression\Operator\Unary::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Operator/Unary.php:57
Method calls 3
- method-call SqlSemantics\Platform\MySql\Statement\Expression\Operator\Arithmetic::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Operator/Arithmetic.php:68
- method-call SqlSemantics\Platform\MySql\Statement\Expression\Operator\Unary::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Operator/Unary.php:61
- method-call SqlSemantics\Platform\MySql\Statement\Expression\Operator\Unary::deriveScalar() packages/sql-semantics-mysql/src/Statement/Expression/Operator/Unary.php:62