Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file int32.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321open!Importopen!Caml.Int32moduleT=structtypet=int32[@@deriving_inlinehash,sexp,sexp_grammar]let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_int32and(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_int32infunx->funcx;;lett_of_sexp=(int32_of_sexp:Ppx_sexp_conv_lib.Sexp.t->t)letsexp_of_t=(sexp_of_int32:t->Ppx_sexp_conv_lib.Sexp.t)let(t_sexp_grammar:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.t)=let(_the_generic_group:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.generic_group)={implicit_vars=["int32"];ggid="\146e\023\249\235eE\139c\132W\195\137\129\235\025";types=["t",Implicit_var0]}inlet(_the_group:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.group)={gid=Ppx_sexp_conv_lib.Lazy_group_id.create();apply_implicit=[int32_sexp_grammar];generic_group=_the_generic_group;origin="int32.ml.T"}inlet(t_sexp_grammar:Ppx_sexp_conv_lib.Sexp.Private.Raw_grammar.t)=Ref("t",_the_group)int_sexp_grammar;;[@@@end]letcompare(x:t)y=comparexyletto_string=to_stringletof_string=of_stringendincludeTincludeComparator.Make(T)letnum_bits=32letfloat_lower_bound=Float0.lower_bound_for_intnum_bitsletfloat_upper_bound=Float0.upper_bound_for_intnum_bitsletfloat_of_bits=float_of_bitsletbits_of_float=bits_of_floatletshift_right_logical=shift_right_logicalletshift_right=shift_rightletshift_left=shift_leftletbit_not=lognotletbit_xor=logxorletbit_or=logorletbit_and=logandletmin_value=min_intletmax_value=max_intletabs=absletpred=predletsucc=succletrem=remletneg=negletminus_one=minus_oneletone=oneletzero=zeroletcompare=compareletto_float=to_floatletof_float_unchecked=of_floatletof_floatf=ifFloat_replace_polymorphic_compare.(>=)ffloat_lower_bound&&Float_replace_polymorphic_compare.(<=)ffloat_upper_boundthenof_floatfelsePrintf.invalid_argf"Int32.of_float: argument (%f) is out of range or NaN"(Float0.boxf)();;includeComparable.Validate_with_zero(structincludeTletzero=zeroend)moduleInfix_compare=structopenPolylet(>=)(x:t)y=x>=ylet(<=)(x:t)y=x<=ylet(=)(x:t)y=x=ylet(>)(x:t)y=x>ylet(<)(x:t)y=x<ylet(<>)(x:t)y=x<>yendmoduleCompare=structincludeInfix_compareletcompare=compareletascending=compareletdescendingxy=compareyxletmin(x:t)y=ifx<ythenxelseyletmax(x:t)y=ifx>ythenxelseyletequal(x:t)y=x=yletbetweent~low~high=low<=t&&t<=highletclamp_uncheckedt~min~max=ift<minthenminelseift<=maxthentelsemaxletclamp_exnt~min~max=assert(min<=max);clamp_uncheckedt~min~max;;letclampt~min~max=ifmin>maxthenOr_error.error_s(Sexp.message"clamp requires [min <= max]"["min",T.sexp_of_tmin;"max",T.sexp_of_tmax])elseOk(clamp_uncheckedt~min~max);;endincludeCompareletinvariant(_:t)=()let(/)=divlet(*)=mullet(-)=sublet(+)=addlet(~-)=negletincrr=r:=!r+oneletdecrr=r:=!r-oneletof_int32t=tletof_int32_exn=of_int32letto_int32t=tletto_int32_exn=to_int32letpopcount=Popcount.int32_popcountmoduleConv=Int_conversionsletof_int=Conv.int_to_int32letof_int_exn=Conv.int_to_int32_exnletof_int_trunc=Conv.int_to_int32_truncletto_int=Conv.int32_to_intletto_int_exn=Conv.int32_to_int_exnletto_int_trunc=Conv.int32_to_int_truncletof_int64=Conv.int64_to_int32letof_int64_exn=Conv.int64_to_int32_exnletof_int64_trunc=Conv.int64_to_int32_truncletto_int64=Conv.int32_to_int64letof_nativeint=Conv.nativeint_to_int32letof_nativeint_exn=Conv.nativeint_to_int32_exnletof_nativeint_trunc=Conv.nativeint_to_int32_truncletto_nativeint=Conv.int32_to_nativeintletto_nativeint_exn=to_nativeintletpowbe=of_int_exn(Int_math.Private.int_pow(to_int_exnb)(to_int_exne))let(**)be=powbeexternalbswap32:t->t="%bswap_int32"letbswap16x=Caml.Int32.shift_right_logical(bswap32x)16modulePow2=structopen!ImportopenInt32_replace_polymorphic_comparemoduleSys=Sys0letraise_s=Error.raise_sletnon_positive_argument()=Printf.invalid_argf"argument must be strictly positive"();;let(lor)=Caml.Int32.logorlet(lsr)=Caml.Int32.shift_right_logicallet(land)=Caml.Int32.logand(** "ceiling power of 2" - Least power of 2 greater than or equal to x. *)letceil_pow2x=ifx<=Caml.Int32.zerothennon_positive_argument();letx=Caml.Int32.predxinletx=xlor(xlsr1)inletx=xlor(xlsr2)inletx=xlor(xlsr4)inletx=xlor(xlsr8)inletx=xlor(xlsr16)inCaml.Int32.succx;;(** "floor power of 2" - Largest power of 2 less than or equal to x. *)letfloor_pow2x=ifx<=Caml.Int32.zerothennon_positive_argument();letx=xlor(xlsr1)inletx=xlor(xlsr2)inletx=xlor(xlsr4)inletx=xlor(xlsr8)inletx=xlor(xlsr16)inCaml.Int32.subx(xlsr1);;letis_pow2x=ifx<=Caml.Int32.zerothennon_positive_argument();xlandCaml.Int32.predx=Caml.Int32.zero;;(* C stubs for int32 clz and ctz to use the CLZ/BSR/CTZ/BSF instruction where possible *)externalclz:(int32[@unboxed])->(int[@untagged])="Base_int_math_int32_clz""Base_int_math_int32_clz_unboxed"[@@noalloc]externalctz:(int32[@unboxed])->(int[@untagged])="Base_int_math_int32_ctz""Base_int_math_int32_ctz_unboxed"[@@noalloc](** Hacker's Delight Second Edition p106 *)letfloor_log2i=ifi<=Caml.Int32.zerothenraise_s(Sexp.message"[Int32.floor_log2] got invalid input"["",sexp_of_int32i]);num_bits-1-clzi;;(** Hacker's Delight Second Edition p106 *)letceil_log2i=ifi<=Caml.Int32.zerothenraise_s(Sexp.message"[Int32.ceil_log2] got invalid input"["",sexp_of_int32i]);(* The [i = 1] check is needed because clz(0) is undefined *)ifCaml.Int32.equaliCaml.Int32.onethen0elsenum_bits-clz(Caml.Int32.predi);;endincludePow2includeConv.Make(T)includeConv.Make_hex(structtypet=int32[@@deriving_inlinecompare,hash]letcompare=(compare_int32:t->t->int)let(hash_fold_t:Ppx_hash_lib.Std.Hash.state->t->Ppx_hash_lib.Std.Hash.state)=hash_fold_int32and(hash:t->Ppx_hash_lib.Std.Hash.hash_value)=letfunc=hash_int32infunx->funcx;;[@@@end]letzero=zeroletneg=(~-)let(<)=(<)letto_stringi=Printf.sprintf"%lx"iletof_strings=Caml.Scanf.sscanfs"%lx"Fn.idletmodule_name="Base.Int32.Hex"end)includePretty_printer.Register(structtypenonrect=tletto_string=to_stringletmodule_name="Base.Int32"end)modulePre_O=structlet(+)=(+)let(-)=(-)let(*)=(*)let(/)=(/)let(~-)=(~-)let(**)=(**)include(Compare:Comparisons.Infixwithtypet:=t)letabs=absletneg=negletzero=zeroletof_int_exn=of_int_exnendmoduleO=structincludePre_OincludeInt_math.Make(structtypenonrect=tincludePre_Oletrem=remletto_float=to_floatletof_float=of_floatletof_string=T.of_stringletto_string=T.to_stringend)let(land)=bit_andlet(lor)=bit_orlet(lxor)=bit_xorletlnot=bit_notlet(lsl)=shift_leftlet(asr)=shift_rightlet(lsr)=shift_right_logicalendincludeO(* [Int32] and [Int32.O] agree value-wise *)