Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - English


signed zero -0

Processing of -0 versus 0

Description

The binary representation of decimal numbers is such that one bit over 64 (= 8 bytes) is dedicated to the sign of the mantissa. This is true for any decimal number, that can be symetrically positive or negative. This also applies to the zero value.

It is possible to force to minus the sign of zero by using the unary minus and writting -0.

Most of operations and functions do not take the sign of zero into account, but there are some exceptions. For instance, the division and atan() do not yield the same results with 0 and -0.

Common interesting cases are illustrated in the following examples.

As 0, -0 is not stored in sparse-encoded matrices, and so is ignored.

Examples

0 and -0 are distinguished:

bitstring([0 ; -0])
[1/0 1/-0]
a = - 0 - 0;    1 / a
a = - 0 + (-0); 1 / a
1 / (0*(-0))
1 / prod([-0 1])
1 ./ ((-0)^[1 2 3])
[atan(0,0), atan(0,-0)]
--> bitstring([0 ; -0])
 ans  =
!0000000000000000000000000000000000000000000000000000000000000000  !
!1000000000000000000000000000000000000000000000000000000000000000  !

--> [1/0 1/-0]
 ans  =
   Inf  -Inf

--> a = - 0 - 0; 1 / a
 ans  =
  -Inf

--> a = - 0 + (-0); 1 / a
 ans  =
  -Inf

--> 1 / (0*(-0))
 ans  =
  -Inf

--> 1 / prod([-0 1])
 ans  =
  -Inf

--> 1 ./ ((-0)^[1 2 3])
 ans  =
  -Inf   Inf  -Inf

--> [atan(0,0), atan(0,-0)]
 ans  =
   0.   3.1415927

.. but + 0 wins:

a = - 0 + 0; 1 / a
--> a = - 0 + 0; 1 / a
 ans  =
   Inf

0 and -0 are NOT distinguished:

[sign(-0), 1/sign(-0)]
sign(0)==sign(-0)
[ isequal(0,-0), 0==-0,  -0<0,  0>-0 ]
1 / sin(-0)
--> [sign(-0), 1/sign(-0)]
 ans  =
   0.   Inf

--> sign(0)==sign(-0)
 ans  =
  T

--> [ isequal(0,-0), 0==-0,  -0<0,  0>-0 ]
 ans  =
  T T F F

--> 1 / sin(-0)
 ans  =
   Inf

The sparse encoding ignores -0 as it does for 0:

sparse([-0 0 1])
1 / sparse(-0)
--> sparse([-0 0 1])
 ans  =
(  1,  3) sparse matrix
(  1,  3)     1.

--> 1 / sparse(-0)
 ans  =
    Inf

See also

Report an issue
<< round Floating point Radix conversions >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:49:15 CEST 2024