Int64.hx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package haxe;
  23. @:include("cpp/Int64.h")
  24. private extern class NativeInt64Helper {
  25. @:native("_hx_int64_make")
  26. static function make(high:Int32, low:Int32):__Int64;
  27. @:native(" ::cpp::Int64Struct")
  28. static function ofInt(value:Int):__Int64;
  29. @:native(" ::cpp::Int64Struct::is")
  30. static function isInt64(d:Dynamic):Bool;
  31. @:native("_hx_int64_is_neg")
  32. static function isNeg(a:__Int64):Bool;
  33. @:native("_hx_int64_is_zero")
  34. static function isZero(a:__Int64):Bool;
  35. @:native("_hx_int64_compare")
  36. static function compare(a:__Int64, b:__Int64):Int;
  37. @:native("_hx_int64_ucompare")
  38. static function ucompare(a:__Int64, b:__Int64):Int;
  39. @:native("_hx_int64_to_string")
  40. static function toString(a:__Int64):String;
  41. @:native("_hx_int64_neg")
  42. static function neg(a:__Int64):__Int64;
  43. @:native("_hx_int64_pre_increment")
  44. static function preIncrement(a:__Int64):__Int64;
  45. @:native("_hx_int64_post_increment")
  46. static function postIncrement(a:__Int64):__Int64;
  47. @:native("_hx_int64_pre_decrement")
  48. static function preDecrement(a:__Int64):__Int64;
  49. @:native("_hx_int64_post_decrement")
  50. static function postDecrement(a:__Int64):__Int64;
  51. @:native("_hx_int64_add")
  52. static function add(a:__Int64, b:__Int64):__Int64;
  53. @:native("_hx_int64_add")
  54. static function addInt(a:__Int64, b:Int):__Int64;
  55. @:native("_hx_int64_sub")
  56. static function sub(a:__Int64, b:__Int64):__Int64;
  57. @:native("_hx_int64_sub")
  58. static function subInt(a:__Int64, b:Int):__Int64;
  59. @:native("_hx_int64_sub")
  60. static function intSub(a:Int, b:__Int64):__Int64;
  61. @:native("_hx_int64_mul")
  62. static function mul(a:__Int64, b:__Int64):__Int64;
  63. @:native("_hx_int64_div")
  64. static function div(a:__Int64, b:__Int64):__Int64;
  65. @:native("_hx_int64_mod")
  66. static function mod(a:__Int64, b:__Int64):__Int64;
  67. @:native("_hx_int64_eq")
  68. static function eq(a:__Int64, b:__Int64):Bool;
  69. @:native("_hx_int64_eq")
  70. static function eqInt(a:__Int64, b:Int):Bool;
  71. @:native("_hx_int64_neq")
  72. static function neq(a:__Int64, b:__Int64):Bool;
  73. @:native("_hx_int64_neq")
  74. static function neqInt(a:__Int64, b:Int):Bool;
  75. @:native("_hx_int64_complement")
  76. static function complement(a:__Int64):__Int64;
  77. @:native("_hx_int64_and")
  78. static function bitAnd(a:__Int64, b:__Int64):__Int64;
  79. @:native("_hx_int64_or")
  80. static function bitOr(a:__Int64, b:__Int64):__Int64;
  81. @:native("_hx_int64_xor")
  82. static function bitXor(a:__Int64, b:__Int64):__Int64;
  83. @:native("_hx_int64_shl")
  84. static function shl(a:__Int64, b:Int):__Int64;
  85. @:native("_hx_int64_shr")
  86. static function shr(a:__Int64, b:Int):__Int64;
  87. @:native("_hx_int64_ushr")
  88. static function ushr(a:__Int64, b:Int):__Int64;
  89. @:native("_hx_int64_high")
  90. static function high(a:__Int64):Int32;
  91. @:native("_hx_int64_low")
  92. static function low(a:__Int64):Int32;
  93. }
  94. private typedef __Int64 = cpp.Int64;
  95. @:coreApi
  96. @:transitive
  97. @:notNull
  98. abstract Int64(__Int64) from __Int64 from Int to __Int64 {
  99. public #if !cppia inline #end function copy():Int64
  100. return this;
  101. public static #if !cppia inline #end function make(high:Int32, low:Int32):Int64 {
  102. return NativeInt64Helper.make(high, low);
  103. }
  104. public static #if !cppia inline #end function ofInt(x:Int):Int64 {
  105. return x;
  106. }
  107. public static #if !cppia inline #end function toInt(x:Int64):Int {
  108. if (x.high != x.low >> 31)
  109. throw "Overflow";
  110. return x.low;
  111. }
  112. @:deprecated('haxe.Int64.is() is deprecated. Use haxe.Int64.isInt64() instead')
  113. inline public static function is(val:Dynamic):Bool {
  114. return val is cpp.Int64;
  115. }
  116. public static #if !cppia inline #end function isInt64(val:Dynamic):Bool
  117. return val is cpp.Int64;
  118. @:deprecated("Use high instead")
  119. public static #if !cppia inline #end function getHigh(x:Int64):Int32
  120. return x.high;
  121. @:deprecated("Use low instead")
  122. public static #if !cppia inline #end function getLow(x:Int64):Int32
  123. return x.low;
  124. public static #if !cppia inline #end function isNeg(x:Int64):Bool
  125. return NativeInt64Helper.isNeg(x);
  126. public static #if !cppia inline #end function isZero(x:Int64):Bool
  127. return NativeInt64Helper.isZero(x);
  128. public static #if !cppia inline #end function compare(a:Int64, b:Int64):Int
  129. return NativeInt64Helper.compare(a, b);
  130. public static #if !cppia inline #end function ucompare(a:Int64, b:Int64):Int
  131. return NativeInt64Helper.ucompare(a, b);
  132. public static #if !cppia inline #end function toStr(x:Int64):String
  133. return cast x.val;
  134. private #if !cppia inline #end function toString():String
  135. return cast this;
  136. public static function parseString(sParam:String):Int64 {
  137. return Int64Helper.parseString(sParam);
  138. }
  139. public static function fromFloat(f:Float):Int64 {
  140. return Int64Helper.fromFloat(f);
  141. }
  142. public static function divMod(dividend:Int64, divisor:Int64):{quotient:Int64, modulus:Int64} {
  143. var q = dividend / divisor;
  144. if (divisor == 0)
  145. throw "divide by zero";
  146. var m = dividend - q * divisor;
  147. return {quotient: q, modulus: m};
  148. }
  149. @:op(-A)
  150. public static #if !cppia inline #end function neg(x:Int64):Int64
  151. return NativeInt64Helper.neg(x);
  152. @:op(++A) private inline function preIncrement():Int64 {
  153. #if cppia
  154. this = this + make(0, 1);
  155. return this;
  156. #else
  157. return NativeInt64Helper.preIncrement(this);
  158. #end
  159. }
  160. @:op(A++) private inline function postIncrement():Int64 {
  161. #if cppia
  162. var result = this;
  163. this = this + make(0, 1);
  164. return result;
  165. #else
  166. return NativeInt64Helper.postIncrement(this);
  167. #end
  168. }
  169. @:op(--A) private inline function preDecrement():Int64 {
  170. #if cppia
  171. untyped this = this - make(0, 1);
  172. return this;
  173. #else
  174. return NativeInt64Helper.preDecrement(this);
  175. #end
  176. }
  177. @:op(A--) private inline function postDecrement():Int64 {
  178. #if cppia
  179. var result = this;
  180. this = this - make(0, 1);
  181. return result;
  182. #else
  183. return NativeInt64Helper.postDecrement(this);
  184. #end
  185. }
  186. @:op(A + B)
  187. public static #if !cppia inline #end function add(a:Int64, b:Int64):Int64
  188. return NativeInt64Helper.add(a, b);
  189. @:op(A + B)
  190. @:commutative
  191. private static #if !cppia inline #end function addInt(a:Int64, b:Int):Int64
  192. return NativeInt64Helper.addInt(a, b);
  193. @:op(A - B)
  194. public static #if !cppia inline #end function sub(a:Int64, b:Int64):Int64 {
  195. return NativeInt64Helper.sub(a, b);
  196. }
  197. @:op(A - B)
  198. private static #if !cppia inline #end function subInt(a:Int64, b:Int):Int64
  199. return NativeInt64Helper.subInt(a, b);
  200. @:op(A - B)
  201. private static #if !cppia inline #end function intSub(a:Int, b:Int64):Int64
  202. return NativeInt64Helper.intSub(a, b);
  203. @:op(A * B)
  204. public static #if !cppia inline #end function mul(a:Int64, b:Int64):Int64
  205. return NativeInt64Helper.mul(a, b);
  206. @:op(A * B)
  207. @:commutative
  208. private static #if !cppia inline #end function mulInt(a:Int64, b:Int):Int64
  209. return mul(a, b);
  210. @:op(A / B)
  211. public static #if !cppia inline #end function div(a:Int64, b:Int64):Int64 {
  212. if (NativeInt64Helper.isZero(b))
  213. throw "divide by zero";
  214. return NativeInt64Helper.div(a, b);
  215. }
  216. @:op(A / B)
  217. private static #if !cppia inline #end function divInt(a:Int64, b:Int):Int64
  218. return div(a, b);
  219. @:op(A / B)
  220. private static #if !cppia inline #end function intDiv(a:Int, b:Int64):Int64
  221. return toInt(div(a, b));
  222. @:op(A % B)
  223. public static #if !cppia inline #end function mod(a:Int64, b:Int64):Int64 {
  224. if (NativeInt64Helper.isZero(b))
  225. throw "divide by zero";
  226. return NativeInt64Helper.mod(a, b);
  227. }
  228. @:op(A % B)
  229. private static #if !cppia inline #end function modInt(a:Int64, b:Int):Int64
  230. return toInt(mod(a, b));
  231. @:op(A % B)
  232. private static #if !cppia inline #end function intMod(a:Int, b:Int64):Int64
  233. return toInt(mod(a, b));
  234. @:op(A == B)
  235. public static #if !cppia inline #end function eq(a:Int64, b:Int64):Bool
  236. return NativeInt64Helper.eq(a, b);
  237. @:op(A == B)
  238. @:commutative
  239. private static #if !cppia inline #end function eqInt(a:Int64, b:Int):Bool
  240. return NativeInt64Helper.eqInt(a, b);
  241. @:op(A != B)
  242. public static #if !cppia inline #end function neq(a:Int64, b:Int64):Bool
  243. return NativeInt64Helper.neq(a, b);
  244. @:op(A != B)
  245. @:commutative
  246. private static #if !cppia inline #end function neqInt(a:Int64, b:Int):Bool
  247. return neq(a, b);
  248. @:op(A < B)
  249. private static #if !cppia inline #end function lt(a:Int64, b:Int64):Bool
  250. return compare(a, b) < 0;
  251. @:op(A < B)
  252. private static #if !cppia inline #end function ltInt(a:Int64, b:Int):Bool
  253. return lt(a, b);
  254. @:op(A < B)
  255. private static #if !cppia inline #end function intLt(a:Int, b:Int64):Bool
  256. return lt(a, b);
  257. @:op(A <= B)
  258. private static #if !cppia inline #end function lte(a:Int64, b:Int64):Bool
  259. return compare(a, b) <= 0;
  260. @:op(A <= B)
  261. private static #if !cppia inline #end function lteInt(a:Int64, b:Int):Bool
  262. return lte(a, b);
  263. @:op(A <= B)
  264. private static #if !cppia inline #end function intLte(a:Int, b:Int64):Bool
  265. return lte(a, b);
  266. @:op(A > B)
  267. private static #if !cppia inline #end function gt(a:Int64, b:Int64):Bool
  268. return compare(a, b) > 0;
  269. @:op(A > B)
  270. private static #if !cppia inline #end function gtInt(a:Int64, b:Int):Bool
  271. return gt(a, b);
  272. @:op(A > B)
  273. private static #if !cppia inline #end function intGt(a:Int, b:Int64):Bool
  274. return gt(a, b);
  275. @:op(A >= B)
  276. private static #if !cppia inline #end function gte(a:Int64, b:Int64):Bool
  277. return compare(a, b) >= 0;
  278. @:op(A >= B)
  279. private static #if !cppia inline #end function gteInt(a:Int64, b:Int):Bool
  280. return gte(a, b);
  281. @:op(A >= B)
  282. private static #if !cppia inline #end function intGte(a:Int, b:Int64):Bool
  283. return gte(a, b);
  284. @:op(~A)
  285. private static #if !cppia inline #end function complement(a:Int64):Int64
  286. return NativeInt64Helper.complement(a);
  287. @:op(A & B)
  288. public static #if !cppia inline #end function and(a:Int64, b:Int64):Int64
  289. return NativeInt64Helper.bitAnd(a, b);
  290. @:op(A | B)
  291. public static #if !cppia inline #end function or(a:Int64, b:Int64):Int64
  292. return NativeInt64Helper.bitOr(a, b);
  293. @:op(A ^ B)
  294. public static #if !cppia inline #end function xor(a:Int64, b:Int64):Int64
  295. return NativeInt64Helper.bitXor(a, b);
  296. @:op(A << B)
  297. public static #if !cppia inline #end function shl(a:Int64, b:Int):Int64
  298. return NativeInt64Helper.shl(a, b);
  299. @:op(A >> B)
  300. public static #if !cppia inline #end function shr(a:Int64, b:Int):Int64
  301. return NativeInt64Helper.shr(a, b);
  302. @:op(A >>> B)
  303. public static #if !cppia inline #end function ushr(a:Int64, b:Int):Int64
  304. return NativeInt64Helper.ushr(a, b);
  305. public var high(get, never):Int32;
  306. private #if !cppia inline #end function get_high():Int32
  307. return NativeInt64Helper.high(this);
  308. public var low(get, never):Int32;
  309. private #if !cppia inline #end function get_low():Int32
  310. return NativeInt64Helper.low(this);
  311. private var val(get, never):__Int64;
  312. private #if !cppia inline #end function get_val():__Int64
  313. return this;
  314. }