{
  "category": "Operators",
  "display_name": "Subtraction (-)",
  "entry_kind": "built_in_operator",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.OP_SUBTRACT",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Of 514 recorded answers (514 workbook cells), 1 do not match: 1 differ in kind or value.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "differs",
    "state_label": "Known larger differences",
    "summary": "Known larger differences on 1 of 514 recorded answers",
    "workbook_corpus": {
      "cells": 517,
      "matched": 513,
      "other_mismatch": 1,
      "pending": 3,
      "worst_ulp": 0
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/arithmetic.rs#L39-L39",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/arithmetic.rs#L56-L61"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "catalogue/arithmetic::binary",
        "catalogue/arithmetic::operands"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/arithmetic.rs#L39-L39",
      "state": "differs",
      "suite": null,
      "summary": "Known larger differences on 1 of 514 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.OP_SUBTRACT.json",
  "name": "OP_SUBTRACT",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n- [`FUNC.OP_ADD`](FUNC.OP_ADD.md) — the additive sibling; same coercion, same broadcast\n  shapes.\n- [`FUNC.OP_NEGATE`](FUNC.OP_NEGATE.md) — prefix `-`. Same character, one operand.\n- `IMSUB` — complex subtraction over text-encoded complex numbers.\n- `DAYS`, `DATEDIF`, `YEARFRAC` — the calendar-aware alternatives to subtracting two date\n  serials. They answer different questions; `-` answers only \"difference of two numbers\".\n\n\n",
    "how-to-implement": "\n### Notes for implementers\n\n\n- Do not \"optimize\" `A - B` into `A + (-B)` or vice versa in a compatibility implementation.\n  The finite results agree, but the call shape, the operand count, and the zero-sign story do\n  not, and a compatibility target should preserve the shape it was given.\n- Cancellation is a modelling problem, not an operator problem. If a workbook loses\n  significance in a subtraction, the fix belongs in the expression that produced the\n  operands, not in a \"better\" subtraction — there is no better subtraction; the IEEE\n  difference is already exact when it matters.\n- Broadcast and coercion are shared machinery. Implementing `-` as a distinct code path from\n  `+` invites the two to drift; the reference implementation keeps them in one family module\n  for exactly that reason.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n- **Text and logical operands.** Governed by the shared to-number rules, exactly as for\n  [`+`](FUNC.OP_ADD.md). Nothing about `-` changes them.\n- **Dates.** Date arithmetic is subtraction: a date is a number wearing a format, so\n  `date2 - date1` is an ordinary difference of serial numbers and the \"number of days\" reading\n  is a presentation fact, not a semantic one. The published result carries no date format of\n  its own; how the host formats the difference cell is host-side adaptation, outside the\n  function's semantics (chapter 03).\n- **Empty and omitted operands.** Per-family policy under chapter 02, and unrecorded here.\n- **Overflow.** The recorded real-result policy is `non_finite=allow`, and\n  `data/functions/FUNC.OP_SUBTRACT.json` marks that axis `default-unexamined`. A difference\n  of two large opposite-signed operands can overflow; what Excel publishes there is not\n  settled on this page.\n\n\n",
    "sources": "- `data/presence/FUNC.OP_SUBTRACT.json` — implementing module\n  `earlier-implementation/operator_arithmetic_family.rs`, the family slug for this\n  page.\n- Handbook `content/model/01-value-universe.md`, `02-coercion-and-lifting.md`,\n  `03-call-pipeline.md`.\n- Sterbenz's lemma is standard floating-point theory (Sterbenz, *Floating-Point Computation*,\n  1974); it is a property of IEEE-754 arithmetic, not a claim about Excel.\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`A - B` converts each operand to a number and returns the IEEE-754 binary64 difference,\nrounded once to nearest with ties to even.\n\nSubtraction is where floating-point arithmetic stops being invisible. Two properties are\nworth stating precisely, because they generate most of the questions readers arrive with:\n\n1. **The subtraction itself is exact when the operands are close.** By Sterbenz's lemma, if\n   `B/2 ≤ A ≤ 2B` then `A - B` is representable exactly and the operation introduces no error\n   at all. The damage was done earlier: catastrophic cancellation is the *revelation* of\n   error already present in `A` and `B`, not error created by `-`.\n2. **`A - B` is not `A + (-B)` in every observable respect.** They agree on the finite\n   arithmetic, but they are different call shapes with different operand counts, and the\n   sign of a zero result differs: `x - x` is a positive zero under round-to-nearest, while\n   `x + (-x)` is too, but `0 - 0` and `0 + -0` are not the same expression. If anything in a\n   workbook can observe the sign of a zero, the rewrite is not neutral.\n\nAs with every operator in this family, the operand conversion is the part that varies: `-`\nnever sees a cell, only values already resolved and coerced by the shared rules of\n[coercion and lifting](../model/02-coercion-and-lifting.md).\n\n\n\n### Arguments\n\n\n| Position | Name | Meaning |\n|---|---|---|\n| 0 | `A` | Minuend. Required. |\n| 1 | `B` | Subtrahend. Required. |\n\nArity is exactly 2; no optional arguments, no defaults. Order is load-bearing —\n`A - B` and `B - A` differ in sign — which distinguishes this row from `+` and `*`.\n\nThe same `-` character in prefix position is [`FUNC.OP_NEGATE`](FUNC.OP_NEGATE.md), a\none-argument operator. Which one a given `-` is depends on the formula grammar, and formula\ngrammar is explicitly out of this Handbook's scope (`CHARTER.md` section 4).\n\n\n"
  },
  "signature": {
    "display": "number1 - number2",
    "parameters": [
      {
        "description": null,
        "name": "number1",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "number2",
        "optional": false,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 2,
        "min": 2
      },
      "category": "Operators",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "NumsToNum",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": null,
        "short_source": "no-short-description"
      },
      "docs": null,
      "entry_kind": "built_in_operator",
      "localized_family_names": null,
      "localized_names": [],
      "signature": {
        "display": "number1 - number2",
        "parameters": [
          {
            "description": null,
            "name": "number1",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "number2",
            "optional": false,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "OP_SUBTRACT",
      "version_marker": null,
      "xlcall": null
    },
    "microsoft": null
  },
  "try_it": {
    "formula": "=5-2"
  },
  "url": "https://handbook.dnacalc.com/functions/OP_SUBTRACT.html",
  "variants": [],
  "versions": []
}