File: testsuite_binaryop_include.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (90 lines) | stat: -rw-r--r-- 2,706 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# testsuite_binaryop_include section for BASIC256

# Modification History
# date		programmer	description
# 20160327	j.m.reneau	original coding

currentsuite = "binaryop"

# this include tests binary operations on integers
# and type conversions
#
# also test integer operations and overflow and underflow

# to hex
call s("-1=ffffffff", tohex(-1), "ffffffff")
call s("2^31-1=7fffffff", tohex(2^31-1), "7fffffff")
call s("-(2^31)=80000000", tohex(-2^31), "80000000")
call s("0=0", tohex(0), "0")


## powers of 2 - twos compliment - not and or
for t = 1 to 31
   a = ~~(2^t-1)
   c = 0-a-1
   b = a & 0xffffffff
   d = c & 0xffffffff
   call n(a + "==" + b, a, b)
   call s("tohex(a)==tohex(b)", tohex(a), tohex(b))
   call n("fromhex(tohex(a))==a)", fromhex(tohex(a)),a)
   call n("typeof(a)==1", typeof(a), 1)
   call n("typeof(b)==1", typeof(b), 1)
   call n(c + "==" + d, c, d)
   call s("tohex(c)==tohex(d)", tohex(c), tohex(d))
   call n("fromhex(tohex(c))==c)", fromhex(tohex(c)),c)
   call n("typeof(c)==1", typeof(c), 1)
   call n("typeof(d)==1", typeof(d), 1)
   
   b = a | 0xffff
   b = b - 65535
   b = a | b
   call n("a=a|0xffff-65535|a", a,b)
   
next t

# test float to integer
maxi = int(2 ^ 31 - 1)
mini = int(-(2 ^31))
call n("maxi=2147483647",maxi,2147483647)
call n("typeof(maxi)",typeof(maxi),1)
call n("mini=-2147483648",mini,-2147483648)
call n("typeof(mini)",typeof(mini),1)

#addition of integers
a = maxi + 1	# overflow
call n("+a=2147483648",a,2147483648)
call n("typeof(a)",typeof(a),2)
a = maxi + -1	# not overflow
call n("+a=2147483646",a,2147483646)
call n("typeof(a)",typeof(a),1)
a = mini + -1	# overflow
call n("+a=-2147483649",a,-2147483649)
call n("typeof(a)",typeof(a),2)
a = mini + 1	# not overflow
call n("+a=-2147483647",a,-2147483647)
call n("typeof(a)",typeof(a),1)

#subtraction of integers
a = maxi - -1	# overflow
call n("-a=2147483648",a,2147483648)
call n("typeof(a)",typeof(a),2)
a = maxi - 1	# not overflow
call n("-a=2147483646",a,2147483646)
call n("typeof(a)",typeof(a),1)
a = mini - 1	# overflow
call n("a=-2147483649",a,-2147483649)
call n("typeof(a)",typeof(a),2)
a = mini - -1	# not overflow
call n("-a=-2147483647",a,-2147483647)
call n("typeof(a)",typeof(a),1)

#multiplication of integers
call n("typeof(maxi \ 9 * 10)",typeof(maxi \ 9 * 10),2)
call n("typeof(mini \ 9 * 10)",typeof(mini \ 9 * 10),2)
call n("typeof(maxi \ 10 * 9)",typeof(maxi \ 10 * 9),1)
call n("typeof(mini \ 10 * 9)",typeof(mini \ 10 * 9),1)
call n("typeof(maxi \ 9 * -10)",typeof(maxi \ 9 * -10),2)
call n("typeof(mini \ 9 * -10)",typeof(mini \ 9 * -10),2)
call n("typeof(maxi \ 10 * -9)",typeof(maxi \ 10 * -9),1)
call n("typeof(mini \ 10 * -9)",typeof(mini \ 10 * -9),1)