1# 2# Various tests of integer arithmetic overflow 3# 4A = 2**62 5print "A = 2**62" 6 7unset overflow 8print "" 9print "unset overflow" 10print "print A, A+A, -3*A" 11print A, A+A, -3*A 12 13set overflow 14print "" 15print "set overflow" 16print "print A, A+A, -3*A" 17print A, A+A, -3*A 18 19set overflow NaN 20print "" 21print "set overflow NaN" 22print "print A, A+A, -3*A" 23print A, A+A, -3*A 24 25print "" 26print "===========================================" 27print " difficult overflow detection for products " 28print "===========================================" 29 30print "set overflow"; set overflow; show overflow 31B = (2**62-1) << 1 32print "B = (2**62-1) << 1" 33print "print B, B+1, B+2, B+3" 34print B, B+1, B+2, B+3 35 36print "" 37print "B/3 = ", B/3 38print "print 3074457345618258602 * 3 : ", 3074457345618258602 * 3, " Should be OK" 39print "print 3074457345618258603 * 3 : ", 3074457345618258603 * 3, " Should overflow" 40 41print "" 42print "print (B-510), int(real(B-510))","\t", (B-510), int(real(B-510)) 43print "print (B-511), int(real(B-511))","\t", (B-511), int(real(B-511)) 44print "" 45print "So any product > 9.22337203685477478e+18 " 46print "may or may not have overflowed and needs additional tests" 47