PageRenderTime 13ms CodeModel.GetById 11ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/tutorial/natural.e

http://github.com/tybor/Liberty
Specman e | 58 lines | 30 code | 13 blank | 15 comment | 0 complexity | f5945576652f6ac8837c5c8d9226a921 MD5 | raw file
 1class NATURAL
 2--
 3-- Well, using NATURAL_8, NATURAL_16, NATURAL_32 and NATURAL_64 classes
 4-- is pretty simple, but an example may be useful.
 5--
 6
 7creation {ANY}
 8	main
 9
10feature {ANY}
11	main is
12		local
13			n8: NATURAL_8; n16: NATURAL_16; n32: NATURAL_32; n64: NATURAL_64
14		do
15			-- To initialize some NATURAL_8 variable with 1:
16			n8 := 1.to_natural_8
17			
18			-- To initialize some NATURAL_16 variable with 1:
19			n16 := 1.to_natural_16
20			
21			-- As you may have guess:
22			n32 := 1.to_natural_32
23			n64 := 1.to_natural_64
24			
25			-- To increment a NATURAL_8:
26			n8 := n8 + 1.to_natural_8
27			
28			-- To increment a NATURAL_16:
29			n16 := n16 + 1.to_natural_16
30			
31			-- As you have guess:
32			n32 := n32 + 1.to_natural_32
33			n64 := n64 + 1.to_natural_64
34			
35			-- Obviously, there are many other available features in NATURAL_* classes.
36			--
37			-- Finally, note that nothing is implicit! There is no automatic promotion/conversion.
38			--
39			-- (The current strict rule applied to NATURAL may be extended to all INTEGER_* types.)
40
41			io.put_string("Maximum NATURAL_8 = ")
42			io.put_natural_8_format(0.to_natural_8.bit_not, 21)
43			io.put_string("%N")
44
45			io.put_string("Maximum NATURAL_16 = ")
46			io.put_natural_16_format(0.to_natural_16.bit_not, 20)
47			io.put_string("%N")
48
49			io.put_string("Maximum NATURAL_32 = ")
50			io.put_natural_32_format(0.to_natural_32.bit_not, 20)
51			io.put_string("%N")
52
53			io.put_string("Maximum NATURAL_64 = ")
54			io.put_natural_64(0.to_natural_64.bit_not)
55			io.put_string("%N")
56		end
57
58end -- class NATURAL