Algorithms icon indicating copy to clipboard operation
Algorithms copied to clipboard

(1.2.17) Rational.java

Open emergencyd opened this issue 4 years ago • 1 comments

在判断是否overflow时,int值好像本身就不会超过max和min,所以判断a + b < MAX这种是不是并不能得到想要的效果? 其次,min应该是2^31,所以是-2147483648,不是-2147483647;

我的想法就是,比如ab>0且a > 0,根据a + b <= max,判断b是否符合b <= max - a...不知道这样是否可以

另外minus和divide也需要判断一下overflow吧

emergencyd avatar Mar 27 '20 09:03 emergencyd

改了一下,可以 review 一下看看有没有问题:https://github.com/jimmysuncpt/Algorithms/commit/80f5deb78ce1527f0058d9b0118df5c305cd25bc & https://github.com/jimmysuncpt/Algorithms/commit/dc44bdb007153f8be10f29ce12984c865342b7f7 @emergencyd

jimmysuncpt avatar Jun 24 '20 12:06 jimmysuncpt