固定宽度整数是否通过乘法分配? [英] Are fixed-width integers distributive over multiplication?
问题描述
对于三个n位带符号整数a
,b
和c
(例如32位),考虑整数整数溢出,a * (b + c) == (a * b) + (a * c)
是否总是正确吗?
For three n-bit signed integers a
, b
, and c
(such as 32-bit), is it always true that a * (b + c) == (a * b) + (a * c)
, taking into account integer overflow?
我认为这与语言无关,但是如果不是,则我对Java的答案特别感兴趣.
I think this is language-independent, but if it's not, I'm specifically interested in the answer for Java.
推荐答案
是的,它成立,因为整数算术是有限环上的模算术.
Yes, it holds, because integer arithmetic is modulo arithmetic over finite rings.
您可以在此处看到一些理论性的讨论: https://math .stackexchange.com/questions/27336/associtivity-commutativity-and-distributivity-of-moduloarimetic
You can see some theoretical discussion here: https://math.stackexchange.com/questions/27336/associativity-commutativity-and-distributivity-of-modulo-arithmetic
这篇关于固定宽度整数是否通过乘法分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!