File: overflow.dem

package info (click to toggle)
gnuplot 6.0.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,940 kB
  • sloc: ansic: 95,319; cpp: 7,590; makefile: 2,470; javascript: 2,328; sh: 1,531; lisp: 664; perl: 304; pascal: 191; tcl: 88; python: 46
file content (46 lines) | stat: -rw-r--r-- 1,162 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# Various tests of integer arithmetic overflow
#
A = 2**62
print "A = 2**62"

unset overflow
print ""
print "unset overflow"
print "print A, A+A, -3*A"
print A, A+A, -3*A

set overflow
print ""
print "set overflow"
print "print A, A+A, -3*A"
print A, A+A, -3*A

set overflow NaN
print ""
print "set overflow NaN"
print "print A, A+A, -3*A"
print A, A+A, -3*A

print ""
print "==========================================="
print " difficult overflow detection for products "
print "==========================================="

print "set overflow"; set overflow; show overflow
B = (2**62-1) << 1
print "B = (2**62-1) << 1"
print "print B, B+1, B+2, B+3"
print B, B+1, B+2, B+3

print ""
print "B/3 = ", B/3
print "print 3074457345618258602 * 3 :  ", 3074457345618258602 * 3, "   Should be OK"
print "print 3074457345618258603 * 3 :  ", 3074457345618258603 * 3, "   Should overflow"

print ""
print "print (B-510), int(real(B-510))","\t", (B-510), int(real(B-510))
print "print (B-511), int(real(B-511))","\t", (B-511), int(real(B-511))
print ""
print "So any product > 9.22337203685477478e+18 "
print "may or may not have overflowed and needs additional tests"