I give you an algorithm called preemptive division: (GNU license) first use the maximum number you consider less than overflow, max divides the first multiplier. If the result is less than the the second number you are goging to multiply, then there is a overflow.
h*c
16 楼
in data structure book, it is called sentry.
l*s
17 楼
这也只能检测溢出吧,出问题一般怎么处理?
【在 g****t 的大作中提到】 : 我多年前做的是用长整数算完,然后返回短整数。
l*s
18 楼
谢谢!
【在 h**********c 的大作中提到】 : I give you an algorithm called preemptive division: (GNU license) : first use the maximum number you consider less than overflow, max divides : the first multiplier. If the result is less than the the second number you : are : goging to multiply, then there is a overflow.
h*c
19 楼
c++ long long 8 bytes or bigger or customize bit set yourself