julia> a = 6.02*10^23
1.2062660515345518e18
julia> b = 6.02e23
6.02e23
julia> a == b
false
Why is a not equals to b?
Any help possible is greatly appreciated!
julia> a = 6.02*10^23
1.2062660515345518e18
julia> b = 6.02e23
6.02e23
julia> a == b
false
Why is a not equals to b?
Any help possible is greatly appreciated!
The reason is because you are using an integer to compute the powers of 10 in the first example, and integers in Julia overflow. See for yourself:
julia> 10^23
200376420520689664
julia> 10.0^23
1.0e23
The first computation yields a number that is larger than the largest 64-bit integer, so it is very wrong.
The second computation uses a floating point number, so it is approximate but it can cover a wider range of values
The Int64(10)^23 has overflowed
julia> 10^23
200376420520689664
julia> big(10)^23
100000000000000000000000
julia> a=6.02*big(10)^23
6.019999999999999573674358543939888477325439453125e+23
julia> b=6.02e23
6.02e23
julia> a == b
false
julia> a - b
-3.84382601456060111522674560546875e+07