In C# integer arithmetic, does a/b/c always equal a/(b*c)?

前端 未结 6 1268
半阙折子戏
半阙折子戏 2021-02-01 11:39

Let a, b and c be non-large positive integers. Does a/b/c always equal a/(b * c) with C# integer arithmetic? For me, in C# it looks like:

int a = 5126, b = 76,          


        
6条回答
  •  悲哀的现实
    2021-02-01 12:22

    If the absolute values of b and c are below about sqrt(2^31) (approx. 46 300), so that b * c will never overflow, the values will always match. If b * c overflows, then an error can be thrown in a checked context, or you can get an incorrect value in an unchecked context.

提交回复
热议问题