addadditionassociativefloating pointfloating point error.sum
I'm new to Matlab
Is there any way to find a, b and c so that (a + b) + c ≠ a + (b + c) I know addition is not associative in floating point, but is there any way to do that in Matlab?
Best Answer
Hi peluca6,
try 0.1 0.2 0.3
These situations are not hard to find. If you just take three random floating point numbers between 0 and 1,
a = rand
b = rand
c = rand
(to make a vector or matrix of random numbers, see 'help rand') and take a look at the quantity
Use the && operator for and, and use the operator to do the or part. So your statement looks like this:
if A && (b || c)
stuff
end
Do not use & and | for those tests, as && and are designed to work explicitly and optimally in if statements. They allow the tests to be short-circuited, so that if the entire test is known to be true or false, the remainder of the tests are not performed, thus saving CPU cycles.
Best Answer