@@ -30,6 +30,10 @@ class MlInt64 {
30
30
this . caml_custom = "_j" ;
31
31
}
32
32
33
+ static UNSIGNED_MAX = new MlInt64 ( 0xffffff , 0xffffff , 0xffff ) ;
34
+ static SIGNED_MAX = new MlInt64 ( 0xffffff , 0xffffff , 0x7fff ) ;
35
+ static SIGNED_MIN = new MlInt64 ( 0x000000 , 0x000000 , 0x8000 ) ;
36
+
33
37
slice ( ) {
34
38
return new MlInt64 ( this . lo , this . mi , this . hi ) ;
35
39
}
@@ -399,12 +403,10 @@ function caml_int64_of_string(s) {
399
403
base = r [ 2 ] ,
400
404
signedness = r [ 3 ] ;
401
405
var base64 = caml_int64_of_int32 ( base ) ;
402
- var threshold = new MlInt64 ( 0xffffff , 0xfffffff , 0xffff ) . udivmod (
403
- base64 ,
404
- ) . quotient ;
406
+ var threshold = MlInt64 . UNSIGNED_MAX . udivmod ( base64 ) . quotient ;
405
407
var c = caml_string_unsafe_get ( s , i ) ;
406
408
var d = caml_parse_digit ( c ) ;
407
- if ( d < 0 || d >= base ) caml_failwith ( "int_of_string " ) ;
409
+ if ( d < 0 || d >= base ) caml_failwith ( "Int64.of_string " ) ;
408
410
var res = caml_int64_of_int32 ( d ) ;
409
411
for ( ; ; ) {
410
412
i ++ ;
@@ -413,15 +415,15 @@ function caml_int64_of_string(s) {
413
415
d = caml_parse_digit ( c ) ;
414
416
if ( d < 0 || d >= base ) break ;
415
417
/* Detect overflow in multiplication base * res */
416
- if ( caml_int64_ult ( threshold , res ) ) caml_failwith ( "int_of_string " ) ;
418
+ if ( caml_int64_ult ( threshold , res ) ) caml_failwith ( "Int64.of_string " ) ;
417
419
d = caml_int64_of_int32 ( d ) ;
418
420
res = caml_int64_add ( caml_int64_mul ( base64 , res ) , d ) ;
419
421
/* Detect overflow in addition (base * res) + d */
420
- if ( caml_int64_ult ( res , d ) ) caml_failwith ( "int_of_string " ) ;
422
+ if ( caml_int64_ult ( res , d ) ) caml_failwith ( "Int64.of_string " ) ;
421
423
}
422
- if ( i !== caml_ml_string_length ( s ) ) caml_failwith ( "int_of_string " ) ;
423
- if ( signedness && caml_int64_ult ( new MlInt64 ( 0 , 0 , 0x8000 ) , res ) )
424
- caml_failwith ( "int_of_string " ) ;
424
+ if ( i !== caml_ml_string_length ( s ) ) caml_failwith ( "Int64.of_string " ) ;
425
+ if ( signedness && caml_int64_ult ( sign < 0 ? MlInt64 . SIGNED_MIN : MlInt64 . SIGNED_MAX , res ) )
426
+ caml_failwith ( "Int64.of_string " ) ;
425
427
if ( sign < 0 ) res = caml_int64_neg ( res ) ;
426
428
return res ;
427
429
}
0 commit comments