Int64.hx 3.9 KB

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