123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* Module [Int64]: 64-bit integers *)externalneg:int64->int64="%int64_neg"externaladd:int64->int64->int64="%int64_add"externalsub:int64->int64->int64="%int64_sub"externalmul:int64->int64->int64="%int64_mul"externaldiv:int64->int64->int64="%int64_div"externalrem:int64->int64->int64="%int64_mod"externallogand:int64->int64->int64="%int64_and"externallogor:int64->int64->int64="%int64_or"externallogxor:int64->int64->int64="%int64_xor"externalshift_left:int64->int->int64="%int64_lsl"externalshift_right:int64->int->int64="%int64_asr"externalshift_right_logical:int64->int->int64="%int64_lsr"externalof_int:int->int64="%int64_of_int"externalto_int:int64->int="%int64_to_int"externalof_float:float->int64="caml_int64_of_float""caml_int64_of_float_unboxed"[@@unboxed][@@noalloc]externalto_float:int64->float="caml_int64_to_float""caml_int64_to_float_unboxed"[@@unboxed][@@noalloc]externalof_int32:int32->int64="%int64_of_int32"externalto_int32:int64->int32="%int64_to_int32"externalof_nativeint:nativeint->int64="%int64_of_nativeint"externalto_nativeint:int64->nativeint="%int64_to_nativeint"letzero=0Lletone=1Lletminus_one=-1Lletsuccn=addn1Lletpredn=subn1Lletabsn=ifn>=0Lthennelsenegnletmin_int=0x8000000000000000Lletmax_int=0x7FFFFFFFFFFFFFFFLletlognotn=logxorn(-1L)letunsigned_to_int=letmax_int=of_intStdlib.max_intinfunn->ifn>=0L&&n<=max_intthenSome(to_intn)elseNoneexternalformat:string->int64->string="caml_int64_format"letto_stringn=format"%d"nexternalof_string:string->int64="caml_int64_of_string"letof_string_opts=trySome(of_strings)withFailure_->Noneexternalbits_of_float:float->int64="caml_int64_bits_of_float""caml_int64_bits_of_float_unboxed"[@@unboxed][@@noalloc]externalfloat_of_bits:int64->float="caml_int64_float_of_bits""caml_int64_float_of_bits_unboxed"[@@unboxed][@@noalloc]typet=int64letcompare(x:t)(y:t)=Stdlib.comparexyletequal(x:t)(y:t)=x=yletunsigned_comparenm=compare(subnmin_int)(submmin_int)letunsigned_ltnm=subnmin_int<submmin_intletminxy:t=ifx<=ythenxelseyletmaxxy:t=ifx>=ythenxelsey(* Unsigned division from signed division of the same bitness.
See Warren Jr., Henry S. (2013). Hacker's Delight (2 ed.), Sec 9-3.
*)letunsigned_divnd=ifd<zerothenifunsigned_ltndthenzeroelseoneelseletq=shift_left(div(shift_right_logicaln1)d)1inletr=subn(mulqd)inifunsigned_ltrdthenqelsesuccqletunsigned_remnd=subn(mul(unsigned_divnd)d)externalseeded_hash_param:int->int->int->'a->int="caml_hash"[@@noalloc]letseeded_hashseedx=seeded_hash_param10100seedxlethashx=seeded_hash_param101000x