3 ms·
I thought this was going to be another example of floating point arithmetic "gotchas" similar to this: #!/usr/bin/python x = 1. a = 1. while a+x > a:
by ColinWright 11y ago
I thought this was going to be another example of floating point arithmetic "gotchas" similar to this:
#!/usr/bin/python
x = 1.
a = 1.
while a+x > a:
x = x/2
print x
b = x
c = x
print a+b+c == c+b+a
print (a+b)+c == a+(b+c)
Always interesting when the arithmetic system you use is non-commutative and non-associative.
*Edited to add the non-associative bit)
- kuschku 11y agoWhich is the case for all vector × vector, vector × matrix and matrix × vector multiplications, for example. (Taking math at university right now as part of studying compsci, non-commutative rings are annoying)
- ColinWright 11y agoYes, but at least they are all still associative. (Original comment edited to deal with that). And non-commutivity is important. You can put on your socks then shoes, but get a different result if you put on your shoes then socks. In general you get different results in rotations if you change the order you do them. Similarly permutations. Non-commutivity is important, it's just that most people don't expect addition to exhibit it. (And by definition, addition is still commutative in non-commutative rings)