Skip to content

Normalize negative zero

normalizeNegativeZero is a built‑in normalization rule that converts JavaScript’s -0 to 0.

This removes a language‑specific numeric edge case while preserving the intended semantic meaning of the value. If the value is not a number, or is not -0, no normalization step is emitted.

Signature

export const normalizeNegativeZero: NormalizationRule<unknown>
(value: unknown, mode: NormalizationMode, path: FieldPath) => NormalizationStep[]

Events

Event code Description
number.now.positive-zero -0 was normalized to 0.

Design rationale

  • Eliminates a JavaScript‑specific numeric quirk (Object.is(-0, 0) to false).
  • Ensures consistent behavior across serialization, comparison, hashing, and downstream validation.
  • Produces a canonical numeric representation without altering user intent.
  • Emits a normalization step only when the input is exactly -0.
  • Classified as lossless normalization. No user data is removed or transformed in meaning.
  • Prevents subtle bugs in equality checks, deduplication, and numeric policies.

Invoke

normalizeNegativeZero runs automatically when:

  • The value is structurally a number.
  • The normalization stage is active.
  • The current mode allows lossless normalization.

Mode behavior:

  • strict: Rule does not run.
  • moderate: Rule runs (this rule is lossless).
  • lax: Rule runs.

Normalization cannot be invoked manually. It is always applied automatically based on structural type and mode.

Examples

Negative zero normalized

const value = -0;

const result = normalizeNegativeZero(value, "strict", "$");
// → [
//     {
//       path: "$",
//       nextValue: 0,
//       lossy: "lossless",
//       events: [
//         JaneEvent{ kind: "info", code: "number.now.positive-zero", ... }
//       ]
//     }
//   ]

Positive zero — no normalization

const result = normalizeNegativeZero(0, "strict", "$");
// → []

Non‑number value

const result = normalizeNegativeZero("0", "strict", "$");
// → []