UInt64.hx 3.3 KB

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