6 ms·
It's not commutative: -0 + 0 = -0, but 0 + -0 = 0.
by lmm 14y ago
It's not commutative: -0 + 0 = -0, but 0 + -0 = 0.
- ColinWright 14y agoAh, that's news to me - can you provide a reference? I'm trying to look it up but my Google-fu is failing to find a specific link. Thanks.
- VMG 14y agoThis paper is referenced in a newsgroup discussion: http://dl.acm.org/citation.cfm?id=156301.156303 http://dl.acm.org/citation.cfm?id=156301.156303 http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.functional/2007-05/msg00256.html http://newsgroups.derkeiler.com/Archive/Comp/comp.lang.funct...
- ColinWright 14y agoSo quoting from the discussion: Oh, of course: for non-NaNs, correctly implemented IEEE arithmetic is "exactly rounded". So addition of non-NaNs must be commutative for any given rounding rule, ...
- notaddicted 14y agoThat's not the behaviour I'm seeing on my machine. (http://codepad.org/rlLuB5VF http://codepad.org/rlLuB5VF) ... but, if you subtract zero from zero the sign depends on the order: http://codepad.org/g9LzZWPd http://codepad.org/g9LzZWPd .
- pascal_cuoq 14y ago(-0.) + (+0.) and (+0.) + (-0.) both evaluate to +0., as any compiler should readily confirm.
- T-hawk 14y agoIs the compiler calculating that at compile time based on the lexical tokens, or at runtime with native CPU floating point instructions? That absolutely matters.
- stephencanon 14y agoN.B.: Except in round-to-minus-infinity, in which case they evaluate to -0.
- homeomorphic 14y agoBut doesn't IEEE-754 consider -0 and 0 equal? From https://en.wikipedia.org/wiki/IEEE_floating_point#Total-ordering_predicate https://en.wikipedia.org/wiki/IEEE_floating_point#Total-orde... : "The normal comparison operations however treat NaNs as unordered and compare −0 and +0 as equal."
- ajross 14y agoRight. -0 == 0. The existence of a "-0" is a property of the underlying representation. The mathematical properties don't know about the sign bit, per se.