@@ -43,13 +43,13 @@ let ( & ) = Caml_nativeint_extern.logand
43
43
let ( << ) = Caml_nativeint_extern. shift_left
44
44
let lognot x = Caml_nativeint_extern. logxor x (- 1n )
45
45
46
- type t = Int64 of { hi : nativeint ; lo : nativeint ; }
46
+ type t = { hi : nativeint ; lo : nativeint ; }
47
47
48
48
external unsafe_to_int64 : t -> int64 = " %identity"
49
49
external unsafe_of_int64 : int64 -> t = " %identity"
50
50
51
51
52
- let mk ~lo ~hi = Int64 {lo = lo >>> 0 ; hi}
52
+ let mk ~lo ~hi = {lo = lo >>> 0 ; hi}
53
53
let min_int = mk ~lo: 0n ~hi: (- 0x80000000n )
54
54
(* The high bits are signed 0x80000000 |~ 0 *)
55
55
@@ -67,10 +67,10 @@ let non_neg_signed x = (x & 0x8000_0000n) = 0n
67
67
let succ_aux ~x_lo ~x_hi =
68
68
let lo = ( x_lo +~ 1n ) |~ 0n in
69
69
mk ~lo ~hi: (( x_hi +~ if lo = 0n then 1n else 0n ) |~ 0n )
70
- let succ (Int64 {lo = x_lo ; hi = x_hi } : t ) =
70
+ let succ ( {lo = x_lo ; hi = x_hi } : t ) =
71
71
succ_aux ~x_lo ~x_hi
72
72
73
- let neg (Int64 {lo;hi} ) =
73
+ let neg ( {lo;hi} ) =
74
74
let other_lo = (lognot lo +~ 1n ) |~ 0n in
75
75
mk ~lo: other_lo
76
76
~hi: ((lognot hi +~ if other_lo = 0n then 1n else 0n ) |~ 0n )
@@ -81,7 +81,7 @@ let neg (Int64 {lo;hi} ) =
81
81
82
82
83
83
let add_aux
84
- (Int64 {lo = x_lo ; hi = x_hi } : t )
84
+ ( {lo = x_lo ; hi = x_hi } : t )
85
85
~y_lo ~y_hi =
86
86
let lo = ( x_lo +~ y_lo) |~ 0n in
87
87
let overflow =
@@ -101,13 +101,13 @@ let add_aux
101
101
102
102
let add
103
103
(self : t )
104
- (Int64 {lo = y_lo ; hi = y_hi } : t ) =
104
+ ( {lo = y_lo ; hi = y_hi } : t ) =
105
105
add_aux self ~y_lo ~y_hi
106
106
107
107
108
- (* let not (Int64 {lo; hi }) = mk ~lo:(lognot lo) ~hi:(lognot hi) *)
108
+ (* let not ( {lo; hi }) = mk ~lo:(lognot lo) ~hi:(lognot hi) *)
109
109
110
- let eq (Int64 x ) (Int64 y ) = x.hi = y.hi && x.lo = y.lo
110
+ let eq ( x ) ( y ) = x.hi = y.hi && x.lo = y.lo
111
111
112
112
let equal_null x y =
113
113
match Js. nullToOption y with
@@ -130,10 +130,10 @@ let sub_aux x ~lo ~hi =
130
130
let y_hi = ((lognot hi +~ if y_lo = 0n then 1n else 0n ) |~ 0n ) in
131
131
add_aux x ~y_lo ~y_hi
132
132
133
- let sub self (Int64 {lo;hi} )= sub_aux self ~lo ~hi
133
+ let sub self ({lo;hi} )= sub_aux self ~lo ~hi
134
134
135
135
136
- let lsl_ (Int64 {lo; hi} as x ) numBits =
136
+ let lsl_ ( {lo; hi} as x ) numBits =
137
137
if numBits = 0 then
138
138
x
139
139
else if numBits > = 32 then
@@ -146,7 +146,7 @@ let lsl_ (Int64 {lo; hi} as x) numBits =
146
146
( hi << numBits))
147
147
148
148
149
- let lsr_ (Int64 {lo; hi} as x ) numBits =
149
+ let lsr_ ( {lo; hi} as x ) numBits =
150
150
if numBits = 0 then x
151
151
else
152
152
let offset = numBits - 32 in
@@ -163,7 +163,7 @@ let lsr_ (Int64 {lo; hi} as x) numBits =
163
163
( lo >>> numBits))
164
164
165
165
166
- let asr_ (Int64 {lo; hi } as x ) numBits =
166
+ let asr_ ( {lo; hi } as x ) numBits =
167
167
if numBits = 0 then
168
168
x
169
169
else
@@ -180,25 +180,25 @@ let asr_ (Int64 {lo; hi } as x) numBits =
180
180
181
181
182
182
let is_zero = function
183
- | Int64 {lo = 0n ; hi = 0n } -> true
183
+ | {lo = 0n ; hi = 0n } -> true
184
184
| _ -> false
185
185
186
186
187
187
188
188
let rec mul this
189
189
other =
190
190
match this, other with
191
- | Int64 {lo = 0n ; hi = 0n }, _
192
- | _, Int64 {lo = 0n ; hi = 0n }
191
+ | {lo = 0n ; hi = 0n }, _
192
+ | _, {lo = 0n ; hi = 0n }
193
193
-> zero
194
- | Int64 {lo = 0n ; hi = - 0x80000000n }, Int64 {lo;_ }
195
- | Int64 {lo;_}, Int64 {lo = 0n ; hi = - 0x80000000n }
194
+ | {lo = 0n ; hi = - 0x80000000n }, {lo;_ }
195
+ | {lo;_}, {lo = 0n ; hi = - 0x80000000n }
196
196
->
197
197
if (lo & 0x1n ) = 0n then
198
198
zero
199
199
else min_int
200
- | Int64 {lo = this_lo; hi = this_hi},
201
- Int64 {lo = other_lo; hi = other_hi }
200
+ | {lo = this_lo; hi = this_hi},
201
+ {lo = other_lo; hi = other_hi }
202
202
->
203
203
if this_hi < 0n then
204
204
if other_hi < 0n then
@@ -251,18 +251,18 @@ let rec mul this
251
251
252
252
(* Dispatched by the compiler, idea: should we do maximum sharing
253
253
*)
254
- let xor (Int64 {lo = this_lo ; hi = this_hi } ) (Int64 {lo = other_lo ; hi = other_hi } ) =
254
+ let xor ( {lo = this_lo ; hi = this_hi } ) ( {lo = other_lo ; hi = other_hi } ) =
255
255
mk
256
256
~lo: (Caml_nativeint_extern. logxor this_lo other_lo)
257
257
~hi: (Caml_nativeint_extern. logxor this_hi other_hi)
258
258
259
259
260
- let or_ (Int64 {lo = this_lo ; hi = this_hi } ) (Int64 {lo = other_lo ; hi = other_hi } ) =
260
+ let or_ ( {lo = this_lo ; hi = this_hi } ) ( {lo = other_lo ; hi = other_hi } ) =
261
261
mk
262
262
~lo: (Caml_nativeint_extern. logor this_lo other_lo)
263
263
~hi: (Caml_nativeint_extern. logor this_hi other_hi)
264
264
265
- let and_ (Int64 {lo = this_lo ; hi = this_hi } ) (Int64 {lo = other_lo ; hi = other_hi } ) =
265
+ let and_ ( {lo = this_lo ; hi = this_hi } ) ( {lo = other_lo ; hi = other_hi } ) =
266
266
mk
267
267
~lo: (Caml_nativeint_extern. logand this_lo other_lo)
268
268
~hi: (Caml_nativeint_extern. logand this_hi other_hi)
@@ -276,7 +276,7 @@ let and_ (Int64 {lo = this_lo; hi= this_hi}) (Int64 {lo = other_lo; hi = other_h
276
276
277
277
type comparison = t -> t -> bool
278
278
279
- let ge (Int64 {hi; lo } : t ) (Int64 {hi = other_hi ; lo = other_lo } ) : bool =
279
+ let ge ( {hi; lo } : t ) ( {hi = other_hi ; lo = other_lo } ) : bool =
280
280
if hi > other_hi then true
281
281
else if hi < other_hi then false
282
282
else lo > = other_lo
@@ -285,7 +285,7 @@ let ge (Int64 {hi; lo } : t) (Int64 {hi = other_hi; lo = other_lo}) : bool =
285
285
286
286
let neq x y = Pervasives. not (eq x y)
287
287
let lt x y = Pervasives. not (ge x y)
288
- let gt (Int64 x ) (Int64 y ) =
288
+ let gt ( x ) ( y ) =
289
289
if x.hi > y.hi then
290
290
true
291
291
else if x.hi < y.hi then
@@ -298,7 +298,7 @@ let le x y = Pervasives.not (gt x y)
298
298
let min x y = if lt x y then x else y
299
299
let max x y = if gt x y then x else y
300
300
301
- let to_float (Int64 {hi; lo} : t ) =
301
+ let to_float ( {hi; lo} : t ) =
302
302
Caml_nativeint_extern. to_float ( hi *~ [% raw{| 0x100000000 | }] +~ lo)
303
303
304
304
@@ -341,15 +341,15 @@ external floor : float -> float = "floor" [@@bs.val] [@@bs.scope "Math"]
341
341
(* either top 11 bits are all 0 or all 1
342
342
when it is all 1, we need exclude -2^53
343
343
*)
344
- let isSafeInteger (Int64 {hi;lo} ) =
344
+ let isSafeInteger ({hi;lo} ) =
345
345
let top11Bits = hi >> 21 in
346
346
top11Bits = 0n ||
347
347
(top11Bits = - 1n &&
348
348
Pervasives. not (lo = 0n && hi = (0xff_e0_00_00n |~ 0n )))
349
349
350
350
external string_of_float : float -> string = " String" [@@ bs.val]
351
351
let rec to_string ( self : int64 ) =
352
- let (Int64 {hi= self_hi;_} as self) = unsafe_of_int64 self in
352
+ let ({hi= self_hi;_} as self) = unsafe_of_int64 self in
353
353
if isSafeInteger self then
354
354
string_of_float (to_float self)
355
355
else
@@ -358,16 +358,16 @@ let rec to_string ( self : int64) =
358
358
if eq self min_int then " -9223372036854775808"
359
359
else " -" ^ to_string (unsafe_to_int64 (neg self))
360
360
else (* large positive number *)
361
- let (Int64 {lo ; hi} as approx_div1) = (of_float (floor (to_float self /. 10. ) )) in
362
- let (Int64 { lo = rem_lo ;hi = rem_hi} ) = (* rem should be a pretty small number *)
361
+ let ( {lo ; hi} as approx_div1) = (of_float (floor (to_float self /. 10. ) )) in
362
+ let ( { lo = rem_lo ;hi = rem_hi} ) = (* rem should be a pretty small number *)
363
363
self
364
364
|. sub_aux ~lo: (lo << 3 ) ~hi: ((lo>>> 29 ) |~ (hi << 3 ))
365
365
|. sub_aux ~lo: (lo << 1 ) ~hi: ((lo >>> 31 ) |~ (hi << 1 ))
366
366
in
367
367
if rem_lo = 0n && rem_hi = 0n then to_string (unsafe_to_int64 approx_div1) ^ " 0"
368
368
else
369
369
if rem_hi < 0n then
370
- (* let (Int64 {lo = rem_lo}) = neg rem in *)
370
+ (* let ( {lo = rem_lo}) = neg rem in *)
371
371
let rem_lo = (lognot rem_lo +~ 1n ) >>> 0 |. Caml_nativeint_extern. to_float in
372
372
let delta = (ceil (rem_lo /. 10. )) in
373
373
let remainder = 10. *. delta -. rem_lo in
@@ -393,31 +393,31 @@ let rec to_string ( self : int64) =
393
393
394
394
let rec div self other =
395
395
match self, other with
396
- | _ , Int64 {lo = 0n ; hi = 0n } ->
396
+ | _ , {lo = 0n ; hi = 0n } ->
397
397
raise Division_by_zero
398
- | Int64 {lo = 0n ; hi = 0n }, _
398
+ | {lo = 0n ; hi = 0n }, _
399
399
-> zero
400
- | Int64 {lo = 0n ; hi = - 0x8000_0000n }, _
400
+ | {lo = 0n ; hi = - 0x8000_0000n }, _
401
401
->
402
402
begin
403
403
if eq other one || eq other neg_one then self
404
404
else if eq other min_int then one
405
405
else
406
- let (Int64 {hi = other_hi;_}) = other in
406
+ let ( {hi = other_hi;_}) = other in
407
407
(* now |other| >= 2, so |this/other| < |MIN_VALUE|*)
408
408
let half_this = asr_ self 1 in
409
409
let approx = lsl_ (div half_this other) 1 in
410
410
match approx with
411
- | Int64 {lo = 0n ; hi = 0n }
411
+ | {lo = 0n ; hi = 0n }
412
412
-> if other_hi < 0n then one else neg one
413
413
| _
414
414
->
415
415
let rem = sub self (mul other approx) in
416
416
add approx (div rem other)
417
417
end
418
- | _, Int64 {lo = 0n ; hi = - 0x8000_0000n }
418
+ | _, {lo = 0n ; hi = - 0x8000_0000n }
419
419
-> zero
420
- | Int64 {lo = _; hi = self_hi}, Int64 {lo = _; hi = other_hi}
420
+ | {lo = _; hi = self_hi}, {lo = _; hi = other_hi}
421
421
->
422
422
if self_hi < 0n then
423
423
if other_hi < 0n then
@@ -439,7 +439,7 @@ let rec div self other =
439
439
else 2. ** (log2 -. 48. ) in
440
440
let approxRes = ref (of_float approx.contents) in
441
441
let approxRem = ref (mul approxRes.contents other) in
442
- while (match approxRem.contents with Int64 {hi;_} -> hi) < 0n || gt approxRem.contents rem.contents do
442
+ while (match approxRem.contents with {hi;_} -> hi) < 0n || gt approxRem.contents rem.contents do
443
443
approx.contents < - approx.contents -. delta;
444
444
approxRes.contents < - of_float approx.contents;
445
445
approxRem.contents < - mul approxRes.contents other
@@ -459,7 +459,7 @@ let div_mod (self : int64) (other : int64) : int64 * int64 =
459
459
let quotient = div (unsafe_of_int64 self) (unsafe_of_int64 other) in
460
460
unsafe_to_int64 quotient, unsafe_to_int64 (sub (unsafe_of_int64 self) (mul quotient (unsafe_of_int64 other)))
461
461
462
- let compare (Int64 self ) (Int64 other ) =
462
+ let compare ( self ) ( other ) =
463
463
let v = Pervasives. compare self.hi other.hi in
464
464
if v = 0 then
465
465
Pervasives. compare self.lo other.lo
@@ -468,13 +468,13 @@ let compare (Int64 self) (Int64 other) =
468
468
let of_int32 (lo : nativeint ) =
469
469
mk ~lo ~hi: (if lo < 0n then - 1n else 0n )
470
470
471
- let to_int32 (Int64 x ) = Caml_nativeint_extern. logor x.lo 0n (* signed integer *)
471
+ let to_int32 ( x ) = Caml_nativeint_extern. logor x.lo 0n (* signed integer *)
472
472
473
473
474
474
(* width does matter, will it be relevant to endian order? *)
475
475
476
476
let to_hex (x : int64 ) =
477
- let Int64 {hi = x_hi; lo = x_lo} = unsafe_of_int64 x in
477
+ let {hi = x_hi; lo = x_lo} = unsafe_of_int64 x in
478
478
let aux v : string =
479
479
Caml_string_extern. of_int (Caml_nativeint_extern. to_int (Caml_nativeint_extern. shift_right_logical v 0 )) ~base: 16
480
480
in
@@ -494,7 +494,7 @@ let to_hex (x : int64) =
494
494
let discard_sign (x : int64 ) : int64 =
495
495
let v = unsafe_of_int64 x in
496
496
unsafe_to_int64
497
- (match v with Int64 v -> Int64 { v with hi = Caml_nativeint_extern. logand 0x7fff_ffffn v.hi })
497
+ (match v with v -> { v with hi = Caml_nativeint_extern. logand 0x7fff_ffffn v.hi })
498
498
499
499
(* >>> 0 does not change its bit representation
500
500
it simply makes sure it is an unsigned integer
@@ -508,7 +508,7 @@ let discard_sign (x : int64) : int64 =
508
508
]}
509
509
*)
510
510
511
- let float_of_bits (Int64 x : t ) : float =
511
+ let float_of_bits ( x : t ) : float =
512
512
([% raw{| function (lo ,hi ){ return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]} |}] : _ -> _ -> _ ) x.lo x.hi
513
513
514
514
(* let to_int32 (x : nativeint) = x |> Caml_nativeint_extern.to_int32
0 commit comments