Home »
Julia
Floating-point zero in Julia
Julia | Floating-point zero: In this tutorial, we are going to learn about the Floating-point zeros with their binary representations in Julia programming language.
Submitted by IncludeHelp, on March 28, 2020
In Julia, floating-point numbers have two zeros,
- Positive zero (+0.0)
- Negative zero (-0.0)
Both are the same. If we compare them by using the Equal to (==) operator, it returns true. Consider the below example,
Example:
# comparing the values
println("0.0 == -0.0: ", 0.0 == -0.0)
# comparing the variables containing zeros
x = 0.0
y = -0.0
println("x == y: ", x == y)
Output
0.0 == -0.0: true
x == y: true
But they don't have the same binary representations.
To check the binary representation of the zeros or any other numbers we can use the bitstring() function.
Example:
# printing the binary
println("bitstring(0.0): ", bitstring(0.0))
println("bitstring(-0.0): ", bitstring(-0.0))
Output
bitstring(0.0): 0000000000000000000000000000000000000000000000000000000000000000
bitstring(-0.0): 1000000000000000000000000000000000000000000000000000000000000000
See the above examples, negative and positive zeros are the same but their binary representations of them are not the same.
Reference: Integers and Floating-Point Numbers