ECMA-262 in Lean

Spec issues · defect of the text · docs/spec-issues/01-number-multiply-zero-sign.md

01. Number::multiply gives +0 for +0 × -5

Location
§6.1.6.1.4 Number::multiply (#sec-numeric-types-number-multiply), step 6, and the clause's description.
Kind
contradiction (a step's result against the clause's description).
Model erratum
NumberMultiplyZeroSign, default reading proposed; its readings: literal, proposed. The proposed reading returns -0𝔽 when one operand is +0𝔽 and the other is negative.
Upstream
Checked 2026-11-19: PR #4072 (open, 2026-11), "Normative: Fix the sign of zero results in Number::multiply", proposes a fix for this case (its description names 0 * -5 and -5 * 0); no issue was found (searched tc39/ecma262's issues and pull requests for "Number::multiply"). PR #2700 (merged 2022-03, commit 4ef927684) added the steps for -0𝔽 operands and left this case.
On this site
NumberMultiplyZeroSign on the Errata page (defect of the text; its default: the proposed reading)

Text

The clause's description:

It performs multiplication according to the rules of IEEE 754-2019 binary double-precision arithmetic, producing the product of x and y.

The last steps:

4. If x is -0𝔽, then …

5. If y is -0𝔽, then …

6. Return 𝔽(ℝ(x) × ℝ(y)).

and §6.1.6.1's definition of 𝔽(x): "… if +0𝔽 was chosen, replace it with -0𝔽 if and only if x < 0; …".

Problem

For x = +0𝔽 and y = -5𝔽, steps 1–5 do not apply. Step 6 computes ℝ(x) × ℝ(y) = 0, a mathematical value with no sign, and 𝔽(0) is +0𝔽. IEEE 754-2019 §6.3 makes the sign of a product the exclusive or of the operands' signs, so the description gives -0𝔽. The two disagree exactly when one operand is +0𝔽 and the other is finite and negative. A product that only rounds to zero is not affected: 𝔽 of a negative real is -0𝔽.

Examples

examples/01-number-multiply-zero-sign.js (outputs: the recorded runs):

print(String(1 / (0 * -5)));   // +0 × -5
print(String(1 / (-5 * 0)));   // -5 × +0
print(String(1 / (0 * 5)));    // +0 × 5
print(String(Object.is(-5 * 0, -0)));
1/(0*-5) 1/(-5*0) 1/(0*5) Object.is(-5*0, -0)
literal step 6 Infinity Infinity Infinity false
V8, SpiderMonkey, JavaScriptCore -Infinity -Infinity Infinity true
formal model, literal reading Infinity Infinity Infinity false
formal model, proposed reading (default) -Infinity -Infinity Infinity true

Proposed wording

--- a/spec.html
+++ b/spec.html
@@ -1817,6 +1817,9 @@
             1. If _y_ is *-0*<sub>𝔽</sub>, then
               1. If _x_ &lt; *-0*<sub>𝔽</sub>, return *+0*<sub>𝔽</sub>.
               1. Return *-0*<sub>𝔽</sub>.
+            1. If _x_ is *+0*<sub>𝔽</sub> or _y_ is *+0*<sub>𝔽</sub>, then
+              1. If _x_ &lt; *-0*<sub>𝔽</sub> or _y_ &lt; *-0*<sub>𝔽</sub>, return *-0*<sub>𝔽</sub>.
+              1. Return *+0*<sub>𝔽</sub>.
             1. Return 𝔽(ℝ(_x_) × ℝ(_y_)).
           </emu-alg>
           <emu-note>

test262

language/expressions/multiplication/S11.5.1_A4_T2.js tests the sign of a product. Its description states the IEEE rule ("negative if the operands have different signs"), but its assertions cover only products of ±1 (1 * -1, …) and products of two signed zeros (0 * -0, -0 * 0, …), not a zero times a nonzero finite Number such as 0 * -5. No test in test262 multiplies +0𝔽 by a negative finite Number, so none fails under the literal text.

The program

The example is a Script. Its runs on the engines and on the model: the examples' runs.

Open in the debugger: The specification Open in the debugger: The specification, with NumberMultiplyZeroSign read as literal text

Source examples/01-number-multiply-zero-sign.js
// Number::multiply step 6 and the sign of an exact zero product.
// Literal step 6: 𝔽(0) is +0, so 1/(+0 * -5) is +Infinity.
// IEEE 754-2019 (the clause's description): -0, so -Infinity.
if (typeof print === "undefined") globalThis.print = console.log;
print(String(1 / (0 * -5)));   // +0 × -5
print(String(1 / (-5 * 0)));   // -5 × +0
print(String(1 / (0 * 5)));    // +0 × 5 (both readings: Infinity)
print(String(Object.is(-5 * 0, -0)));