Permalink
Browse files

[cleanup] bslint64: Avoid code duplication

  • Loading branch information...
1 parent 6418550 commit 424027fad5bc8dd60585ada93bef27472a51e561 @BourgerieQuentin BourgerieQuentin committed Sep 21, 2012
@@ -16,34 +16,6 @@ function buffer_of_binary(bin){
}
/**
- * @register {int -> int64} i64_of_int_signed
- */
-function i64_of_int_signed(i)
-{
- var msk = 0;
- if (i >= 0 && i <= IMAX32) { return {h:0, l:i}; };
- if (i < IMIN53 || i > IMAX53) { return NAN(); };
- if (i < 0) { i = 0x20000000000000 + i; msk = 0xffe00000};
- var h = Math.floor(i / POW2_32);
- var l = i % POW2_32;
- return {h:h+msk, l:l};
-}
-
-/**
- * @register {int64 -> int} i64_to_int_signed
- */
-function i64_to_int_signed(i64)
-{
- if (is_nan(i64)) return NAN();
- var sign = land(i64.h,0xffe00000);
- if (sign != 0) {
- if (sign != 0xffe00000) throw "Int64.to_int_signed: int64 too big for signed int";
- return -(0x20000000000000 - (((i64.h & 0x001fffff) * 0x100000000) + i64.l));
- } else
- return (i64.h * 0x100000000) + i64.l;
-}
-
-/**
* @register {int -> binary} create
*/
function binary_create(hint) {
@@ -187,6 +187,28 @@ function int_ordering(c1,c2) {
/** @endModule */
+function i64_of_int_signed(i)
+{
+ var msk = 0;
+ if (i >= 0 && i <= IMAX32) { return {h:0, l:i}; };
+ if (i < IMIN53 || i > IMAX53) { return NAN(); };
+ if (i < 0) { i = 0x20000000000000 + i; msk = 0xffe00000};
+ var h = Math.floor(i / POW2_32);
+ var l = i % POW2_32;
+ return {h:h+msk, l:l};
+}
+
+function i64_to_int_signed(i64)
+{
+ if (is_nan(i64)) return NaN;
+ var sign = land(i64.h,0xffe00000);
+ if (sign != 0) {
+ if (sign != 0xffe00000) throw "Int64.to_int_signed: int64 too big for signed int";
+ return -(0x20000000000000 - (((i64.h & 0x001fffff) * 0x100000000) + i64.l));
+ } else
+ return (i64.h * 0x100000000) + i64.l;
+}
+
/** @module BslInt64 */
// Note these are *unsigned* int64 routines.
@@ -261,17 +283,8 @@ function int64_of_int(i) {
}
/**
- * @register {int -> int64} of_int_signed
+ * @register {int -> int64} of_int_signed i64_of_int_signed
*/
-function int64_of_int_signed(i) {
- var msk = 0;
- if (i >= 0 && i <= IMAX32) { return {h:0, l:i}; };
- if (i < IMIN53 || i > IMAX53) { return NAN(); };
- if (i < 0) { i = 0x20000000000000 + i; msk = 0xffe00000};
- var h = Math.floor(i / POW2_32);
- var l = i % POW2_32;
- return {h:h+msk, l:l};
-}
/**
* @register {int64 -> int} to_int
@@ -283,23 +296,14 @@ function int64_to_int(i64) {
}
/**
- * @register {int64 -> int} to_int_signed
+ * @register {int64 -> int} to_int_signed i64_to_int_signed
*/
-function int64_to_int_signed(i64) {
- if (is_nan(i64)) return NaN;
- var sign = land(i64.h,0xffe00000);
- if (sign != 0) {
- if (sign != 0xffe00000) throw "Int64.to_int_signed: int64 too big for signed int";
- return -(0x20000000000000 - (((i64.h & 0x001fffff) * 0x100000000) + i64.l));
- } else
- return (i64.h * 0x100000000) + i64.l;
-}
/**
* @register {int64 -> option(int)} to_int_signed_opt
*/
function int64_to_int_signed_opt(i64){
- var i = int64_to_int_signed(i64)
+ var i = i64_to_int_signed(i64)
if(isNaN(i)) return null;
else return i;
}
@@ -119,7 +119,7 @@ Int64 = {{
to_int = %%BslNumber.BslInt64.to_int%% : int64 -> int
/** Convert signed int into int64 **/
- of_int_signed = %%BslBinary.i64_of_int_signed%% : int -> int64
+ of_int_signed = %%BslNumber.BslInt64.of_int_signed%% : int -> int64
/**
* Convert int64 into signed int if the int64 is not greater than max_int.
@@ -130,7 +130,7 @@ Int64 = {{
to_int_signed_opt = %%BslNumber.BslInt64.to_int_signed_opt%% : int64 -> option(int)
/** Convert int64 to signed int, may raise overflow **/
- to_int_signed = %%BslBinary.i64_to_int_signed%% : int64 -> int
+ to_int_signed = %%BslNumber.BslInt64.to_int_signed%% : int64 -> int
/** Generate int64 from decimal string **/
of_string = %%BslNumber.BslInt64.of_string%% : string -> int64

0 comments on commit 424027f

Please sign in to comment.