-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 8.3.11
-
Component/s: Query Execution
-
Query Execution
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
$add of two -0.0 doubles gives 0.0 in the classic engine and -0.0 in SBE. Inside $group the expression runs in SBE under the default engine selection, so the result depends on the engine; $atan2 with -1 as the second argument makes the sign visible: π with the classic engine, -π with SBE.
- classic engine: internalQueryFrameworkControl: forceClassicEngine. Check: the explain line in the output shows explainVersion 1, with $group after $cursor.
- SBE: default internalQueryFrameworkControl: trySbeRestricted: the whole pipeline, including $group, runs in SBE. Check: the explain line shows explainVersion 2 with GROUP in the SBE plan.
Expected: The same value with both engines; under IEEE 754 -0.0 + -0.0 is -0.0, so _id: -3.141592653589793.
Actual: Classic engine: _id: 3.141592653589793. Default (trySbeRestricted, SBE): _id: -3.141592653589793.
The classic AddState starts with longTotal = 0 and doubleTotal = 0; the first double operand converts the long total to a double, giving +0.0, and +0.0 + -0.0 is +0.0. SBE adds the operands pairwise (genericAdd), so -0.0 + -0.0 stays -0.0. Decimal -0 behaves the same way. $subtract and $multiply agree between the engines on the same inputs. master has the same code.
- classic: src/mongo/db/exec/expression/evaluate_math.cpp#L201-L202 — AddState totals start at 0; the first double operand takes doubleTotal = longTotal (L92)
- SBE: src/mongo/db/exec/sbe/values/arith_common.cpp#L259-L264 — genericAdd: binary IEEE addition
Found with AI assistance.