Please, check
0.4^2 == 0.16
0.4 == 0.16^0.5
It's not a statistical issue. It's a rounding issue in floating point arithmetics in the language.
The same applies to Python
0.4**2 == 0.16
0.4 == 0.16**0.5
None of these floating point numbers is stored in a computer's memory as two- or three-decimal digits, but rather in a binary format.
For instance, 0.16
(8-byte) is stored as 11111111000100011110101110000101000111101011100001010001111011, while 0.4**2
gives us 11111111000100011110101110000101000111101011100001010001111100.
You can play with this decimal to binary conversion using the following Python code:
import struct
bin(struct.unpack('!Q',struct.pack('!d',0.16))[0])
bin(struct.unpack('!Q',struct.pack('!d',0.4**2))[0])
all.equal
function instead to acknowledge the fact that your machine represents real numbers as floating-point numbers with a specific numerical precision. The documentation ofall.equal
also explains.Machine$double.eps
. $\endgroup$print(x <- 1 + 1e-15, 17); sqrt(x)^2 == x
$\endgroup$