Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
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)] 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]) ans = ( 1, 3) sparse matrix ( 1, 3) 1. --> 1 / sparse(-0) ans = Inf
See also
- %inf — infinity
- zeros — matriz feita de zeros
- sparse — definição de matriz esparsa
- number_properties — determina parâmetros de ponto flutuante
- Signed zero on Wikipedia
Report an issue | ||
<< round | Ponto flutuante | Integer representation >> |