---
title: "Saxon treats an untyped -0.00 as not equal to 0, unlike the XPath spec"
url: "https://www.dariuszparys.com/notes/saxon-untyped-negative-zero-not-equal-to-zero"
author: "Dariusz Parys"
published: 2026-12-04T00:00:00.000Z
description: "Saxon-HE 12.8 compares an untyped -0.00 as unequal to 0 because it orders -0 before +0, while the XPath spec casts the value to xs:double and treats -0 and +0 as equal, so zero-amount rules fire differently than in a spec-conforming evaluator."
tags:
  - "E-Invoicing"
  - "Testing"
---

# Saxon treats an untyped -0.00 as not equal to 0, unlike the XPath spec

## Context

An own XPath 2.0 / Schematron evaluator was compared against Saxon-HE 12.8 and validators built on it, running business rules over XML documents validated without a schema, so every value is untyped. Hundreds of hand-written cases agreed. About 1 in 15 randomised documents did not, always on rules that compare an amount with zero.

## Insight

By the spec, in a general comparison an untyped value compared with a number is cast to `xs:double`, and -0 equals +0. Saxon-HE 12.8 orders such comparisons totally, as Java does: -0 sorts before +0, NaN above everything. Measured with 159 expressions:

```xpath
(: nz is the untyped text "-0.00", pz the untyped text "0.00" :)
nz = 0e0                          (: false in Saxon, true by the spec :)
pz = -0e0                         (: false in Saxon :)
nz = 0                            (: false: integer comparison only for integer text such as "-0" :)
xs:double('-0.00') = 0            (: true: typed values are not affected :)
round(sum(m) * 100) div 100 = pz  (: false when the sum is a tiny negative, because the result is -0 :)
```

Two consequences:

- A rule like "tax amount = 0" fires when a document writes `-0.00`, for example a credit note computed as -100 × 0 %.
- A rounded total that comes out as -0 does not equal a written `0.00`.

Takeaways:

- **Decide which one you follow.** Strictly by the spec, your engine passes documents that the Saxon-based validator your counterpart runs will reject. Reproducing Saxon took about 40 lines, behind a switch, and gave zero deviations.
- **Keep a randomised oracle comparison as a permanent test.** No hand-written case and no official example file contained a negative zero; only random data found it.

## Docs

A docs check did not find this described on these pages (no claim beyond them):

- [XPath 3.1 conformance, Saxon 12 documentation](https://www.saxonica.com/html/documentation12/conformance/xpath31.html)
- [Saxonica forum: clarification xs:float(-0.0), Saxon 8.1](https://saxonica.plan.io/boards/3/topics/4738), a lead only: there Michael Kay states that XPath requires -0 and +0 to compare equal.
