Operators
Subtraction (-)
Known larger differences on 1 of 514 recorded answers
Of 514 recorded answers (514 workbook cells), 1 do not match: 1 differ in kind or value. How we measure this · See the Rust code
No local names are recorded for this entry.
What it does
number1 - number2
A - B converts each operand to a number and returns the IEEE-754 binary64 difference,
rounded once to nearest with ties to even.
Subtraction is where floating-point arithmetic stops being invisible. Two properties are worth stating precisely, because they generate most of the questions readers arrive with:
- The subtraction itself is exact when the operands are close. By Sterbenz's lemma, if
B/2 ≤ A ≤ 2BthenA - Bis representable exactly and the operation introduces no error at all. The damage was done earlier: catastrophic cancellation is the revelation of error already present inAandB, not error created by-. A - Bis notA + (-B)in every observable respect. They agree on the finite arithmetic, but they are different call shapes with different operand counts, and the sign of a zero result differs:x - xis a positive zero under round-to-nearest, whilex + (-x)is too, but0 - 0and0 + -0are not the same expression. If anything in a workbook can observe the sign of a zero, the rewrite is not neutral.
As with every operator in this family, the operand conversion is the part that varies: -
never sees a cell, only values already resolved and coerced by the shared rules of
coercion and lifting.
Arguments
| Position | Name | Meaning |
|---|---|---|
| 0 | A | Minuend. Required. |
| 1 | B | Subtrahend. Required. |
Arity is exactly 2; no optional arguments, no defaults. Order is load-bearing —
A - B and B - A differ in sign — which distinguishes this row from + and *.
The same - character in prefix position is FUNC.OP_NEGATE, a
one-argument operator. Which one a given - is depends on the formula grammar, and formula
grammar is explicitly out of this Handbook's scope (CHARTER.md section 4).
Try it
Quirks
Result and edge cases
- Text and logical operands. Governed by the shared to-number rules, exactly as for
+. Nothing about-changes them. - Dates. Date arithmetic is subtraction: a date is a number wearing a format, so
date2 - date1is an ordinary difference of serial numbers and the "number of days" reading is a presentation fact, not a semantic one. The published result carries no date format of its own; how the host formats the difference cell is host-side adaptation, outside the function's semantics (chapter 03). - Empty and omitted operands. Per-family policy under chapter 02, and unrecorded here.
- Overflow. The recorded real-result policy is
non_finite=allow, anddata/functions/FUNC.OP_SUBTRACT.jsonmarks that axisdefault-unexamined. A difference of two large opposite-signed operands can overflow; what Excel publishes there is not settled on this page.
How to implement
Notes for implementers
- Do not "optimize"
A - BintoA + (-B)or vice versa in a compatibility implementation. The finite results agree, but the call shape, the operand count, and the zero-sign story do not, and a compatibility target should preserve the shape it was given. - Cancellation is a modelling problem, not an operator problem. If a workbook loses significance in a subtraction, the fix belongs in the expression that produced the operands, not in a "better" subtraction — there is no better subtraction; the IEEE difference is already exact when it matters.
- Broadcast and coercion are shared machinery. Implementing
-as a distinct code path from+invites the two to drift; the reference implementation keeps them in one family module for exactly that reason.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.
- infix · 1 lines · calc-func/src/catalogue/arithmetic.rs on GitHubCatalogueEntry::operator(MINUS, "-", Notation::Infix, NUMBERS, minus)
minus · 6 lines · calc-func/src/catalogue/arithmetic.rs on GitHubfn minus(
arguments: &[CalcValue],
services: &mut EvalServices<'_>,
) -> Result<CalcValue, FunctionFault> {
binary(MINUS, arguments, services, Site::subtract)
}
Kernels shared with other functions
Argument and result plumbing
CatalogueEntry::operatorcatalogue
No implementation has been published with a Handbook test suite for this function.
Version differences
No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.
Alternatives
Relationships
FUNC.OP_ADD— the additive sibling; same coercion, same broadcast shapes.FUNC.OP_NEGATE— prefix-. Same character, one operand.IMSUB— complex subtraction over text-encoded complex numbers.DAYS,DATEDIF,YEARFRAC— the calendar-aware alternatives to subtracting two date serials. They answer different questions;-answers only "difference of two numbers".
Named variants
No named variants are recorded yet.
Suggest a correction or contribute an implementation · For agents