/tutorial/natural.e

http://github.com/tybor/Liberty · Specman e · 58 lines · 30 code · 13 blank · 15 comment · 0 complexity · f5945576652f6ac8837c5c8d9226a921 MD5 · raw file

  1. class 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. creation {ANY}
  7. main
  8. feature {ANY}
  9. main is
  10. local
  11. n8: NATURAL_8; n16: NATURAL_16; n32: NATURAL_32; n64: NATURAL_64
  12. do
  13. -- To initialize some NATURAL_8 variable with 1:
  14. n8 := 1.to_natural_8
  15. -- To initialize some NATURAL_16 variable with 1:
  16. n16 := 1.to_natural_16
  17. -- As you may have guess:
  18. n32 := 1.to_natural_32
  19. n64 := 1.to_natural_64
  20. -- To increment a NATURAL_8:
  21. n8 := n8 + 1.to_natural_8
  22. -- To increment a NATURAL_16:
  23. n16 := n16 + 1.to_natural_16
  24. -- As you have guess:
  25. n32 := n32 + 1.to_natural_32
  26. n64 := n64 + 1.to_natural_64
  27. -- Obviously, there are many other available features in NATURAL_* classes.
  28. --
  29. -- Finally, note that nothing is implicit! There is no automatic promotion/conversion.
  30. --
  31. -- (The current strict rule applied to NATURAL may be extended to all INTEGER_* types.)
  32. io.put_string("Maximum NATURAL_8 = ")
  33. io.put_natural_8_format(0.to_natural_8.bit_not, 21)
  34. io.put_string("%N")
  35. io.put_string("Maximum NATURAL_16 = ")
  36. io.put_natural_16_format(0.to_natural_16.bit_not, 20)
  37. io.put_string("%N")
  38. io.put_string("Maximum NATURAL_32 = ")
  39. io.put_natural_32_format(0.to_natural_32.bit_not, 20)
  40. io.put_string("%N")
  41. io.put_string("Maximum NATURAL_64 = ")
  42. io.put_natural_64(0.to_natural_64.bit_not)
  43. io.put_string("%N")
  44. end
  45. end -- class NATURAL