Int64.hx 3.5 KB

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