Int64.hx 11 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. import haxe.Int64Helper;
  24. @:notNull
  25. @:include("cpp/Int64.h")
  26. @:native("cpp::Int64Struct")
  27. private extern class ___Int64 {
  28. function get():cpp.Int64;
  29. @:native("_hx_int64_make")
  30. static function make(high:Int32, low:Int32):__Int64;
  31. @:native(" ::cpp::Int64Struct")
  32. static function ofInt(value:Int):__Int64;
  33. @:native(" ::cpp::Int64Struct::is")
  34. static function isInt64(d:Dynamic):Bool;
  35. @:native("_hx_int64_is_neg")
  36. static function isNeg(a:__Int64):Bool;
  37. @:native("_hx_int64_is_zero")
  38. static function isZero(a:__Int64):Bool;
  39. @:native("_hx_int64_compare")
  40. static function compare(a:__Int64, b:__Int64):Int;
  41. @:native("_hx_int64_ucompare")
  42. static function ucompare(a:__Int64, b:__Int64):Int;
  43. @:native("_hx_int64_to_string")
  44. static function toString(a:__Int64):String;
  45. @:native("_hx_int64_neg")
  46. static function neg(a:__Int64):__Int64;
  47. @:native("_hx_int64_pre_increment")
  48. static function preIncrement(a:__Int64):__Int64;
  49. @:native("_hx_int64_post_increment")
  50. static function postIncrement(a:__Int64):__Int64;
  51. @:native("_hx_int64_pre_decrement")
  52. static function preDecrement(a:__Int64):__Int64;
  53. @:native("_hx_int64_post_decrement")
  54. static function postDecrement(a:__Int64):__Int64;
  55. @:native("_hx_int64_add")
  56. static function add(a:__Int64, b:__Int64):__Int64;
  57. @:native("_hx_int64_add")
  58. static function addInt(a:__Int64, b:Int):__Int64;
  59. @:native("_hx_int64_sub")
  60. static function sub(a:__Int64, b:__Int64):__Int64;
  61. @:native("_hx_int64_sub")
  62. static function subInt(a:__Int64, b:Int):__Int64;
  63. @:native("_hx_int64_sub")
  64. static function intSub(a:Int, b:__Int64):__Int64;
  65. @:native("_hx_int64_mul")
  66. static function mul(a:__Int64, b:__Int64):__Int64;
  67. @:native("_hx_int64_div")
  68. static function div(a:__Int64, b:__Int64):__Int64;
  69. @:native("_hx_int64_mod")
  70. static function mod(a:__Int64, b:__Int64):__Int64;
  71. @:native("_hx_int64_eq")
  72. static function eq(a:__Int64, b:__Int64):Bool;
  73. @:native("_hx_int64_eq")
  74. static function eqInt(a:__Int64, b:Int):Bool;
  75. @:native("_hx_int64_neq")
  76. static function neq(a:__Int64, b:__Int64):Bool;
  77. @:native("_hx_int64_neq")
  78. static function neqInt(a:__Int64, b:Int):Bool;
  79. @:native("_hx_int64_complement")
  80. static function complement(a:__Int64):__Int64;
  81. @:native("_hx_int64_and")
  82. static function bitAnd(a:__Int64, b:__Int64):__Int64;
  83. @:native("_hx_int64_or")
  84. static function bitOr(a:__Int64, b:__Int64):__Int64;
  85. @:native("_hx_int64_xor")
  86. static function bitXor(a:__Int64, b:__Int64):__Int64;
  87. @:native("_hx_int64_shl")
  88. static function shl(a:__Int64, b:Int):__Int64;
  89. @:native("_hx_int64_shr")
  90. static function shr(a:__Int64, b:Int):__Int64;
  91. @:native("_hx_int64_ushr")
  92. static function ushr(a:__Int64, b:Int):__Int64;
  93. @:native("_hx_int64_high")
  94. static function high(a:__Int64):Int32;
  95. @:native("_hx_int64_low")
  96. static function low(a:__Int64):Int32;
  97. }
  98. private typedef __Int64 = ___Int64;
  99. @:coreApi
  100. abstract Int64(__Int64) from __Int64 to __Int64 {
  101. public #if !cppia inline #end function copy():Int64
  102. return this;
  103. public static #if !cppia inline #end function make(high:Int32, low:Int32):Int64 {
  104. return __Int64.make(high, low);
  105. }
  106. @:from
  107. public static #if !cppia inline #end function ofInt(x:Int):Int64 {
  108. return __Int64.ofInt(x);
  109. }
  110. public static #if !cppia inline #end function toInt(x:Int64):Int {
  111. if (x.high != x.low >> 31)
  112. throw "Overflow";
  113. return x.low;
  114. }
  115. @:deprecated('haxe.Int64.is() is deprecated. Use haxe.Int64.isInt64() instead')
  116. inline public static function is(val:Dynamic):Bool {
  117. return isInt64(val);
  118. }
  119. public static #if !cppia inline #end function isInt64(val:Dynamic):Bool
  120. return __Int64.isInt64(val);
  121. @:deprecated("Use high instead")
  122. public static #if !cppia inline #end function getHigh(x:Int64):Int32
  123. return x.high;
  124. @:deprecated("Use low instead")
  125. public static #if !cppia inline #end function getLow(x:Int64):Int32
  126. return x.low;
  127. public static #if !cppia inline #end function isNeg(x:Int64):Bool
  128. return __Int64.isNeg(x);
  129. public static #if !cppia inline #end function isZero(x:Int64):Bool
  130. return __Int64.isZero(x);
  131. public static #if !cppia inline #end function compare(a:Int64, b:Int64):Int
  132. return __Int64.compare(a, b);
  133. public static #if !cppia inline #end function ucompare(a:Int64, b:Int64):Int
  134. return __Int64.ucompare(a, b);
  135. public static #if !cppia inline #end function toStr(x:Int64):String
  136. return x.toString();
  137. private #if !cppia inline #end function toString():String
  138. return __Int64.toString(this);
  139. public static function parseString(sParam:String):Int64 {
  140. return Int64Helper.parseString(sParam);
  141. }
  142. public static function fromFloat(f:Float):Int64 {
  143. return Int64Helper.fromFloat(f);
  144. }
  145. public static function divMod(dividend:Int64, divisor:Int64):{quotient:Int64, modulus:Int64} {
  146. var q = dividend / divisor;
  147. if (isZero(divisor))
  148. throw "divide by zero";
  149. var m = dividend - q * divisor;
  150. return {quotient: q, modulus: m};
  151. }
  152. @:op(-A)
  153. public static #if !cppia inline #end function neg(x:Int64):Int64
  154. return __Int64.neg(x);
  155. @:op(++A) private inline function preIncrement():Int64 {
  156. #if cppia
  157. this = this + make(0, 1);
  158. return this;
  159. #else
  160. return __Int64.preIncrement(this);
  161. #end
  162. }
  163. @:op(A++) private inline function postIncrement():Int64 {
  164. #if cppia
  165. var result = this;
  166. this = this + make(0, 1);
  167. return result;
  168. #else
  169. return __Int64.postIncrement(this);
  170. #end
  171. }
  172. @:op(--A) private inline function preDecrement():Int64 {
  173. #if cppia
  174. untyped this = this - make(0, 1);
  175. return this;
  176. #else
  177. return __Int64.preDecrement(this);
  178. #end
  179. }
  180. @:op(A--) private inline function postDecrement():Int64 {
  181. #if cppia
  182. var result = this;
  183. this = this - make(0, 1);
  184. return result;
  185. #else
  186. return __Int64.postDecrement(this);
  187. #end
  188. }
  189. @:op(A + B)
  190. public static #if !cppia inline #end function add(a:Int64, b:Int64):Int64
  191. return __Int64.add(a, b);
  192. @:op(A + B)
  193. @:commutative
  194. private static #if !cppia inline #end function addInt(a:Int64, b:Int):Int64
  195. return __Int64.addInt(a, b);
  196. @:op(A - B)
  197. public static #if !cppia inline #end function sub(a:Int64, b:Int64):Int64 {
  198. return __Int64.sub(a, b);
  199. }
  200. @:op(A - B)
  201. private static #if !cppia inline #end function subInt(a:Int64, b:Int):Int64
  202. return __Int64.subInt(a, b);
  203. @:op(A - B)
  204. private static #if !cppia inline #end function intSub(a:Int, b:Int64):Int64
  205. return __Int64.intSub(a, b);
  206. @:op(A * B)
  207. public static #if !cppia inline #end function mul(a:Int64, b:Int64):Int64
  208. return __Int64.mul(a, b);
  209. @:op(A * B)
  210. @:commutative
  211. private static #if !cppia inline #end function mulInt(a:Int64, b:Int):Int64
  212. return mul(a, b);
  213. @:op(A / B)
  214. public static #if !cppia inline #end function div(a:Int64, b:Int64):Int64 {
  215. if (__Int64.isZero(b))
  216. throw "divide by zero";
  217. return __Int64.div(a, b);
  218. }
  219. @:op(A / B)
  220. private static #if !cppia inline #end function divInt(a:Int64, b:Int):Int64
  221. return div(a, b);
  222. @:op(A / B)
  223. private static #if !cppia inline #end function intDiv(a:Int, b:Int64):Int64
  224. return toInt(div(a, b));
  225. @:op(A % B)
  226. public static #if !cppia inline #end function mod(a:Int64, b:Int64):Int64 {
  227. if (__Int64.isZero(b))
  228. throw "divide by zero";
  229. return __Int64.mod(a, b);
  230. }
  231. @:op(A % B)
  232. private static #if !cppia inline #end function modInt(a:Int64, b:Int):Int64
  233. return toInt(mod(a, b));
  234. @:op(A % B)
  235. private static #if !cppia inline #end function intMod(a:Int, b:Int64):Int64
  236. return toInt(mod(a, b));
  237. @:op(A == B)
  238. public static #if !cppia inline #end function eq(a:Int64, b:Int64):Bool
  239. return __Int64.eq(a, b);
  240. @:op(A == B)
  241. @:commutative
  242. private static #if !cppia inline #end function eqInt(a:Int64, b:Int):Bool
  243. return __Int64.eqInt(a, b);
  244. @:op(A != B)
  245. public static #if !cppia inline #end function neq(a:Int64, b:Int64):Bool
  246. return __Int64.neq(a, b);
  247. @:op(A != B)
  248. @:commutative
  249. private static #if !cppia inline #end function neqInt(a:Int64, b:Int):Bool
  250. return neq(a, b);
  251. @:op(A < B)
  252. private static #if !cppia inline #end function lt(a:Int64, b:Int64):Bool
  253. return compare(a, b) < 0;
  254. @:op(A < B)
  255. private static #if !cppia inline #end function ltInt(a:Int64, b:Int):Bool
  256. return lt(a, b);
  257. @:op(A < B)
  258. private static #if !cppia inline #end function intLt(a:Int, b:Int64):Bool
  259. return lt(a, b);
  260. @:op(A <= B)
  261. private static #if !cppia inline #end function lte(a:Int64, b:Int64):Bool
  262. return compare(a, b) <= 0;
  263. @:op(A <= B)
  264. private static #if !cppia inline #end function lteInt(a:Int64, b:Int):Bool
  265. return lte(a, b);
  266. @:op(A <= B)
  267. private static #if !cppia inline #end function intLte(a:Int, b:Int64):Bool
  268. return lte(a, b);
  269. @:op(A > B)
  270. private static #if !cppia inline #end function gt(a:Int64, b:Int64):Bool
  271. return compare(a, b) > 0;
  272. @:op(A > B)
  273. private static #if !cppia inline #end function gtInt(a:Int64, b:Int):Bool
  274. return gt(a, b);
  275. @:op(A > B)
  276. private static #if !cppia inline #end function intGt(a:Int, b:Int64):Bool
  277. return gt(a, b);
  278. @:op(A >= B)
  279. private static #if !cppia inline #end function gte(a:Int64, b:Int64):Bool
  280. return compare(a, b) >= 0;
  281. @:op(A >= B)
  282. private static #if !cppia inline #end function gteInt(a:Int64, b:Int):Bool
  283. return gte(a, b);
  284. @:op(A >= B)
  285. private static #if !cppia inline #end function intGte(a:Int, b:Int64):Bool
  286. return gte(a, b);
  287. @:op(~A)
  288. private static #if !cppia inline #end function complement(a:Int64):Int64
  289. return __Int64.complement(a);
  290. @:op(A & B)
  291. public static #if !cppia inline #end function and(a:Int64, b:Int64):Int64
  292. return __Int64.bitAnd(a, b);
  293. @:op(A | B)
  294. public static #if !cppia inline #end function or(a:Int64, b:Int64):Int64
  295. return __Int64.bitOr(a, b);
  296. @:op(A ^ B)
  297. public static #if !cppia inline #end function xor(a:Int64, b:Int64):Int64
  298. return __Int64.bitXor(a, b);
  299. @:op(A << B)
  300. public static #if !cppia inline #end function shl(a:Int64, b:Int):Int64
  301. return __Int64.shl(a, b);
  302. @:op(A >> B)
  303. public static #if !cppia inline #end function shr(a:Int64, b:Int):Int64
  304. return __Int64.shr(a, b);
  305. @:op(A >>> B)
  306. public static #if !cppia inline #end function ushr(a:Int64, b:Int):Int64
  307. return __Int64.ushr(a, b);
  308. public var high(get, never):Int32;
  309. private #if !cppia inline #end function get_high():Int32
  310. return __Int64.high(this);
  311. public var low(get, never):Int32;
  312. private #if !cppia inline #end function get_low():Int32
  313. return __Int64.low(this);
  314. }