-
Notifications
You must be signed in to change notification settings - Fork 144
f32::ZERO
and f64::ZERO
are not the additive identity
#352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For some context, this was a pretty recent change in Rust for
I still have some mild misgivings about it:
|
I agree about the performance implications, but the question really amounts to "should Regarding the mathematical misgivings, it is best to interpret |
Considering that ZERO, the zero trait, zero() all are documented as returning "the additive identity", I think it makes sense to return -0.0 for the reasons explained above.
I don't really see the difference between this argument and "why should anyone care about the difference between +0.0 and -0.0" - If they don't care, then it should be fine to define ZERO as -0.0. If they do care, then they may be surprised when they add -0.0 to 0.0 and get 0.0.
I think it's reasonable to say that those that want that property can initialize with |
They can't do that for a generic |
Actually, let's ask -- @bluss @jturner314, how would you feel about this in |
|
Another solution is to take the outcome of this discussion and use it to update the docstring, ie:
|
I don't think negative zeros would be appropriate for ndarray's use case, it would surprise all users and cost performance as noted. cc @akern40 (Unfortunately I think we'd need another Zero trait that gives positive zeros - in general, not thinking of ndarray, if this change was implemented so it would be "a bit" churny.) |
Same, I don’t think the enforcement of strict additive identity at the bit levels is worth the performance hit regarding allocating zero tensors. Personally I never think of zero as |
f32::ZERO
andf64::ZERO
are currently+0.0
, which is not the additive identity. For non-NaNf32
andf64
under default rounding, the additive identity is-0.0
and not+0.0
, since(-0.0) + (+0.0) == (+0.0)
but(-0.0) + (-0.0) == (-0.0)
. (EDIT: interpreting==
bitwise.)The text was updated successfully, but these errors were encountered: