# Comparison of negative and positive floating-point zero

**URL:** https://swi-prolog.discourse.group/t/comparison-of-negative-and-positive-floating-point-zero/1005
**Category:** Help!
**Created:** [July 29, 2019, 11:01pm UTC](https://swi-prolog.discourse.group/t/comparison-of-negative-and-positive-floating-point-zero/1005 "2019-07-29T23:01:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![aminemarref](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@aminemarref](https://swi-prolog.discourse.group/u/aminemarref)
#### Post date: [July 29, 2019, 11:01pm UTC](https://swi-prolog.discourse.group/t/comparison-of-negative-and-positive-floating-point-zero/1005/1 "2019-07-29T23:01:17Z")

</div>

Hello,

The following evaluates to false in SWI-Prolog:

`?- -0.0 == 0.0.`  
`false`

In my program’s calculations, I would like `-0.0` to be equal to `0.0`.

Is this a bug or a feature? and how can I get the equality `-0.0 == 0.0` to work without introducing a special predicate to handle this?

Cheers,  
Amine.

---

<div class="post-metadata">

### Author: ![PaulBrownMagic](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/paulbrownmagic/32/211_2.png) [@PaulBrownMagic](https://swi-prolog.discourse.group/u/PaulBrownMagic)
#### Post date: [July 29, 2019, 11:05pm UTC](https://swi-prolog.discourse.group/t/comparison-of-negative-and-positive-floating-point-zero/1005/2 "2019-07-29T23:05:55Z")

</div>

Hi Amine,

You can use the numerical equality comparison operator `=:=/2`:

```prolog
?- 0.0 =:= -0.0.
true.

?= -0.0 =:= 0.
true.

?- 0 =:= 0.0.
true.

```

---

<div class="post-metadata">

### Author: ![aminemarref](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@aminemarref](https://swi-prolog.discourse.group/u/aminemarref)
#### Post date: [July 29, 2019, 11:14pm UTC](https://swi-prolog.discourse.group/t/comparison-of-negative-and-positive-floating-point-zero/1005/3 "2019-07-29T23:14:24Z")

</div>

Thanks a lot for the prompt help 🙂 Now things are great.  
For the record, the equality `-0.0 == 0.0` works fine in Sicstus (from which I am porting my program).

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [July 30, 2019, 6:54am UTC](https://swi-prolog.discourse.group/t/comparison-of-negative-and-positive-floating-point-zero/1005/4 "2019-07-30T06:54:18Z")

</div>

Possibly the SICStus reader simply maps -0.0 to 0.0. The status of the IEEE float specs for the `unusual’ numbers in Prolog is quite unclear. SWI (and ECLiPSe) handle -0.0, ±Inf and NaN. Most systems don’t, where -0.0 == 0.0 and the others cannot be created as the operations that would create them raise an exception rather then the special value. Raising exceptions is defined by ISO and also done in SWI, but special floats can be exchanged through the foreign interface and be read and written such that we can support serializations (e.g., XML) that support these values.
