UInt64.hx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package eval.integers;
  2. /**
  3. Unsigned 64-bit integer type and operations.
  4. **/
  5. @:coreType abstract UInt64 {
  6. /** The greatest representable UInt64 value. */
  7. extern static public final MAX:UInt64;
  8. /** The integer `0` */
  9. extern static public final ZERO:UInt64;
  10. /** The integer `1` */
  11. extern static public final ONE:UInt64;
  12. /**
  13. Convert the given int value to an unsigned integer.
  14. **/
  15. static public function ofInt(i:Int):UInt64;
  16. /**
  17. Parse the given string value to an unsigned integer.
  18. <<<<<<< HEAD
  19. =======
  20. >>>>>>> development
  21. Throws if the given string is not a valid representation of an unsigned
  22. integer.
  23. **/
  24. static public function ofString(s:String):UInt64;
  25. /**
  26. Returns the greater of `a` and `b`.
  27. **/
  28. static public function max(a:UInt64, b:UInt64):UInt64;
  29. /**
  30. Returns the lesser of `a` and `b`.
  31. **/
  32. static public function min(a:UInt64, b:UInt64):UInt64;
  33. /**
  34. Compare given values.
  35. Returns `0` if the values are equal.
  36. Returns negative integer if `a` is lesser than `b`.
  37. Returns positive integer if `a` is greater than `b`.
  38. **/
  39. static public function compare(a:UInt64, b:UInt64):Int;
  40. /**
  41. Convert to an integer value.
  42. The 64-bit unsigned integer is taken modulo 2{^32}, i.e. the top 32 bits
  43. are lost during the conversion.
  44. **/
  45. public function toInt():Int;
  46. /**
  47. Convert to a signed integer value.
  48. **/
  49. public function toInt64():Int64;
  50. /**
  51. Return the string representation of this value.
  52. **/
  53. public function toString():String;
  54. /**
  55. Successor.
  56. **/
  57. public function successor():String;
  58. /**
  59. Predecessor.
  60. **/
  61. public function predecessor():String;
  62. /**
  63. Integer remainder.
  64. Throws if the divisor is zero.
  65. **/
  66. public function remainder(u:UInt64):UInt64;
  67. function add(u:UInt64):UInt64;
  68. function sub(u:UInt64):UInt64;
  69. function mul(u:UInt64):UInt64;
  70. function div(u:UInt64):UInt64;
  71. function logand(u:UInt64):UInt64;
  72. function logor(u:UInt64):UInt64;
  73. function logxor(u:UInt64):UInt64;
  74. function shift_left(i:Int):UInt64;
  75. function shift_right(i:Int):UInt64;
  76. function lognot():UInt64;
  77. @:op(A + B) inline function _add(u:UInt64):UInt64 return this.add(u);
  78. @:op(A - B) inline function _sub(u:UInt64):UInt64 return this.sub(u);
  79. @:op(A * B) inline function _mul(u:UInt64):UInt64 return this.mul(u);
  80. @:op(A / B) inline function _div(u:UInt64):UInt64 return this.div(u);
  81. @:op(A & B) inline function _logand(u:UInt64):UInt64 return this.logand(u);
  82. @:op(A | B) inline function _logor(u:UInt64):UInt64 return this.logor(u);
  83. @:op(A ^ B) inline function _logxor(u:UInt64):UInt64 return this.logxor(u);
  84. @:op(A << B) inline function _shift_left(i:Int):UInt64 return this.shift_left(i);
  85. @:op(A >> B) inline function _shift_right(i:Int):UInt64 return this.shift_right(i);
  86. @:op(~A) inline function _lognot():UInt64 return this.lognot();
  87. @:op(A != B) static inline function eq(a:UInt64, b:UInt64):Bool return compare(a, b) != 0;
  88. @:op(A == B) static inline function ne(a:UInt64, b:UInt64):Bool return compare(a, b) == 0;
  89. @:op(A < B) static inline function lt(a:UInt64, b:UInt64):Bool return compare(a, b) < 0;
  90. @:op(A > B) static inline function gt(a:UInt64, b:UInt64):Bool return compare(a, b) > 0;
  91. @:op(A <= B) static inline function lte(a:UInt64, b:UInt64):Bool return compare(a, b) <= 0;
  92. @:op(A >= B) static inline function gte(a:UInt64, b:UInt64):Bool return compare(a, b) >= 0;
  93. }