固定宽度整数是否通过乘法分配? [英] Are fixed-width integers distributive over multiplication?

查看:98
本文介绍了固定宽度整数是否通过乘法分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于三个n位带符号整数abc(例如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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆