QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: EricE on March 16, 2020, 01:22:04 pm
-
What value can be used for the QB64's Machine Epsilon for DOUBLE variables?
This would be a value such that the DOUBLE variable x value would be considered zero if the following criteria is met.
ABS(x) < EPSILON
From the Wiki article on Machine Epsilon,
https://en.wikipedia.org/wiki/Machine_epsilon (https://en.wikipedia.org/wiki/Machine_epsilon)
we get code that approximates this value to within a factor of two.
Translated into QB64 the code is:
epsilon = 1.0
WHILE (1.0 + 0.5 * epsilon
) <> 1.0 epsilon = 0.5 * epsilon
When this code is run on a Windows 10 64-bit computer using the 32-bit version of QB64, this value is computed.
epsilon = 1.192092895507812D-7
-
If we change the code to converge towards zero instead of one, we get a smaller value.
epsilon = 1.401298464324817D-45
This might be the better value to use when testing if a determinant value is zero.
epsilon = 1.0
WHILE (0.5 * epsilon
) <> 0.0 epsilon = 0.5 * epsilon