123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126typet=intletzero=0letone=1letminus_one=(-1)letnegx=(-x)letaddab=a+bletsubab=a-bletmulab=a*blet_unsigned_comparenm=letopenNativeintincompare(subnmin_int)(submmin_int)let_unsigned_divnd=letopenNativeintinifd<zerothenif_unsigned_comparend<0thenzeroelseoneelseletq=shift_left(div(shift_right_logicaln1)d)1inletr=subn(mulqd)inif_unsigned_comparerd>=0thensuccqelseqletdivab=Nativeint.to_int(_unsigned_div(Nativeint.of_inta)(Nativeint.of_intb))letremab=amodbletsuccx=x+1letpredx=x-1letabsx=letmask=xasrSys.int_sizein(* extract sign: -1 if signed, 0 if not signed *)(x+mask)lxormaskletmax_int=Int32.(to_intmax_int)letmin_int=Int32.(to_intmin_int)letlogandab=alandbletlogorab=alorbletlogxorab=alxorbletlognotx=lnotxletshift_leftan=alslnletshift_rightan=aasrnletshift_right_logicalan=alsrnexternalof_int:int->t="%identity"externalof_unsigned_int:int->t="%identity"externalto_int:t->int="%identity"externalto_unsigned_int:t->int="%identity"letto_int64=Stdlib.Int64.of_intletof_int64=Stdlib.Int64.to_intletof_floatx=int_of_floatxletto_floatx=(* allocation *)float_of_intxletof_stringx=int_of_stringxletof_string_optx=try(* allocation *)Some(of_stringx)withFailure_->Noneletto_stringx=string_of_intxletcompare:int->int->int=funab->a-bletequal:int->int->bool=funab->a=bletinvalid_argfmt=Format.kasprintfinvalid_argfmtletuint32_max=(0xfffflsl16)lor0xffffletint32_sign_maskl=0x80000000lletint32_sign_mask=1lsl31letint32_maxl=0x7ffffffflletint32_max=0x7fffffffletto_int32x=lettruncated=xlanduint32_maxinifx=truncatedthenInt32.of_inttruncatedelseifcompare0x>0&&(xlsr31)=uint32_maxthenInt32.(logorint32_sign_maskl(of_int(xlandint32_max)))elseinvalid_arg"Optint.to_int32: %d can not fit into a 32 bits integer"xletto_unsigned_int32x=lettruncated=xlanduint32_maxinifx<>truncatedtheninvalid_arg"Optint.to_unsigned_int32: %d can not fit into a 32 bits integer"xelseInt32.of_inttruncatedletof_int32=letnegative_int32_mask=(int32_maxlsl32)lorint32_sign_maskinfunx->ifx<0lthenletx=Int32.logandxint32_maxlinnegative_int32_masklor(Int32.to_intx)elseInt32.to_intxletof_unsigned_int32x=ifx<0lthenletx=Int32.logandx(Int32.lognotint32_sign_maskl)in(Int32.to_intx)lorint32_sign_maskelseInt32.to_intxletppppf(x:t)=Format.fprintfppf"%d"xletencoded_size=4externalset_32:bytes->int->int32->unit="%caml_bytes_set32u"externalget_32:string->int->int32="%caml_string_get32"externalswap32:int32->int32="%bswap_int32"letencodebuf~offt=lett=to_int32tinlett=ifnotSys.big_endianthenswap32telsetinset_32bufofftletdecodebuf~off=lett=get_32bufoffinlett=ifnotSys.big_endianthenswap32telsetinof_int32tmoduleInfix=structlet(+)ab=addablet(-)ab=subablet(*)ab=mulablet(%)ab=remablet(/)ab=divablet(land)ab=logandablet(lor)ab=logorablet(lsr)ab=shift_rightablet(lsl)ab=shift_leftablet(&&)=(land)let(||)=(lor)let(>>)=(lsr)let(<<)=(lsl)end