text
stringlengths
12
786k
let effective_start_time ~ mode ( x : Transition . t ) = let open Int63 . O in match ( mode : Mode . t ) with | Absolute -> x . start_time_in_seconds_since_epoch | Date_and_ofday -> x . start_time_in_seconds_since_epoch + x . new_regime . utc_offset_in_seconds ; ;
let index_lower_bound_contains_seconds_since_epoch t index ~ mode seconds = index < 0 || Int63 . ( >= ) seconds ( effective_start_time ~ mode t . transitions . ( index ) ) ; ;
let index_upper_bound_contains_seconds_since_epoch t index ~ mode seconds = index + 1 >= Array . length t . transitions || Int63 . ( < ) seconds ( effective_start_time ~ mode t . transitions . ( index + 1 ) ) ; ;
let binary_search_index_of_seconds_since_epoch t ~ mode seconds : Index . t = Array . binary_search_segmented t . transitions ` Last_on_left ~ segment_of ( : fun transition -> if Int63 . ( <= ) ( effective_start_time transition ~ mode ) seconds then ` Left else ` Right ) |> Option . value ~ default : Index . before_first_transition ; ;
let index_of_seconds_since_epoch t ~ mode seconds = let index = let index = t . last_regime_index in if not ( index_lower_bound_contains_seconds_since_epoch t index ~ mode seconds ) then ( let index = index - 1 in if not ( index_lower_bound_contains_seconds_since_epoch t index ~ mode seconds ) then binary_search_index_of_seconds_since_epoch t ~ mode seconds else index ) else if not ( index_upper_bound_contains_seconds_since_epoch t index ~ mode seconds ) then ( let index = index + 1 in if not ( index_upper_bound_contains_seconds_since_epoch t index ~ mode seconds ) then binary_search_index_of_seconds_since_epoch t ~ mode seconds else index ) else index in t . last_regime_index <- index ; index ; ;
module Time_in_seconds : sig include Zone_intf . Time_in_seconds module Span = struct type t = Int63 . t let of_int63_seconds = ident let to_int63_seconds_round_down_exn = ident end module Absolute = struct type t = Int63 . t let of_span_since_epoch = ident let to_span_since_epoch = ident end module Date_and_ofday = struct type t = Int63 . t let of_synthetic_span_since_epoch = ident let to_synthetic_span_since_epoch = ident end include Absolute end
let index t time = Time_in_seconds . to_span_since_epoch time |> Time_in_seconds . Span . to_int63_seconds_round_down_exn |> index_of_seconds_since_epoch t ~ mode : Absolute ; ;
let index_of_date_and_ofday t time = Time_in_seconds . Date_and_ofday . to_synthetic_span_since_epoch time |> Time_in_seconds . Span . to_int63_seconds_round_down_exn |> index_of_seconds_since_epoch t ~ mode : Date_and_ofday ; ;
let index_has_prev_clock_shift t index = index >= 0 && index < Array . length t . transitions
let index_has_next_clock_shift t index = index_has_prev_clock_shift t ( index + 1 )
let index_prev_clock_shift_time_exn t index = let transition = t . transitions . ( index ) in transition . start_time_in_seconds_since_epoch |> Time_in_seconds . Span . of_int63_seconds |> Time_in_seconds . of_span_since_epoch ; ;
let index_next_clock_shift_time_exn t index = index_prev_clock_shift_time_exn t ( index + 1 ) ; ;
let index_prev_clock_shift_amount_exn t index = let transition = t . transitions . ( index ) in let after = transition . new_regime in let before = if index = 0 then t . default_local_time_type else t . transitions . ( index - 1 ) . new_regime in Int63 . ( - ) after . utc_offset_in_seconds before . utc_offset_in_seconds |> Time_in_seconds . Span . of_int63_seconds ; ;
let index_next_clock_shift_amount_exn t index = index_prev_clock_shift_amount_exn t ( index + 1 ) ; ;
let index_abbreviation_exn t index = let regime = get_regime_exn t index in regime . abbrv ; ;
let index_offset_from_utc_exn t index = let regime = get_regime_exn t index in Time_in_seconds . Span . of_int63_seconds regime . utc_offset_in_seconds ; ;
module type Time_in_seconds = sig module Span : sig type t val of_int63_seconds : Int63 . t -> t val to_int63_seconds_round_down_exn : t -> Int63 . t end module Date_and_ofday : sig type t val of_synthetic_span_since_epoch : Span . t -> t val to_synthetic_span_since_epoch : t -> Span . t end type t val of_span_since_epoch : Span . t -> t val to_span_since_epoch : t -> Span . t end
module type S = sig type t [ @@ deriving sexp_of , compare ] val input_tz_file : zonename : string -> filename : string -> t val likely_machine_zones : string list ref val of_utc_offset : hours : int -> t val utc : t val name : t -> string val original_filename : t -> string option val digest : t -> Md5 . t option module Time_in_seconds : Time_in_seconds val reset_transition_cache : t -> unit module Index : sig type t [ @@ immediate ] val next : t -> t val prev : t -> t end val index : t -> Time_in_seconds . t -> Index . t val index_of_date_and_ofday : t -> Time_in_seconds . Date_and_ofday . t -> Index . t val index_offset_from_utc_exn : t -> Index . t -> Time_in_seconds . Span . t val index_abbreviation_exn : t -> Index . t -> string val index_has_prev_clock_shift : t -> Index . t -> bool val index_prev_clock_shift_time_exn : t -> Index . t -> Time_in_seconds . t val index_prev_clock_shift_amount_exn : t -> Index . t -> Time_in_seconds . Span . t val index_has_next_clock_shift : t -> Index . t -> bool val index_next_clock_shift_time_exn : t -> Index . t -> Time_in_seconds . t val index_next_clock_shift_amount_exn : t -> Index . t -> Time_in_seconds . Span . t end
module type S_stable = sig type t module Full_data : sig module V1 : Stable_module_types . S0_without_comparator with type t = t end end
module type Zone = sig module type S = S module type S_stable = S_stable include S module Stable : S_stable with type t := t end
let month_limits = Map . Poly . of_alist_exn [ 1 , 31 ; 2 , 28 ; 3 , 31 ; 4 , 30 ; 5 , 31 ; 6 , 30 ; 7 , 31 ; 8 , 31 ; 9 , 30 ; 10 , 31 ; 11 , 30 ; 12 , 31 ]
let random_time state = let year = 1970 + Random . State . int state 67 in let month = 1 + ( Random . State . int state 12 ) in let day = 1 + ( Random . State . int state ( Map . find_exn month_limits month ) ) in let hour = Random . State . int state 12 + 8 in let min = Random . State . int state 60 in let sec = Random . State . int state 60 in let ms = Random . State . int state 1_000 in let mic = Random . State . int state 1_000 in ( year , month , day , hour , min , sec , ms , mic ) ; ;
let random_time_str state = let year , month , day , hour , min , sec , ms , _mic = random_time state in sprintf " % d . -% 2d . -% 2d . % 2d . :% 2d . :% 2d . . % 3d000 " year month day hour min sec ms ; ;
let random_tm state = let ( year , month , day , hour , min , sec , _ , _ ) = random_time state in { Unix . tm_sec = sec ; tm_min = min ; tm_hour = hour ; tm_mday = day ; tm_mon = month ; tm_year = year - 1900 ; tm_wday = 0 ; tm_yday = 0 ; tm_isdst = false ; }
let zone_tests = ref [ ]
let add name test = zone_tests := ( name >:: test ) :: ! zone_tests
let add_random_string_round_trip_test state s1 = let pos_neg = if Random . State . bool state then " " + else " " - in let distance = Int . to_string ( Random . State . int state 10 + 1 ) in let s2 = String . concat [ s1 ; pos_neg ; distance ; " : 00 " ] in let zone = ( force Time . Zone . local ) in let s1 = let t = Time . of_string s1 in let utc_epoch = Time . Zone . date_and_ofday_of_absolute_time zone t |> Time . Zone . absolute_time_of_date_and_ofday Time . Zone . utc in let f = Time . diff utc_epoch t |> Time . Span . to_sec |> Float . to_int in s1 ^ ( if f = 0 then " Z " else Printf . sprintf " %+ 03d : 00 " ( f / 3600 ) ) in add ( " roundtrip string " ^ s1 ) ( fun ( ) -> " s1 " @? ( s1 = ( Time . to_string_abs ( Time . of_string s1 ) ~ zone ) ) ; " s2 - time " @? ( let s2_time1 = Time . of_string s2 in let s2_time2 = Time . of_string ( Time . to_string_abs s2_time1 ~ zone ) in Time . ( . ) = s2_time1 s2_time2 ) )
let add_random_string_round_trip_tests state = for _ = 1 to 100 do add_random_string_round_trip_test state ( random_time_str state ) done ; ; ;
let add_roundtrip_conversion_test state ( zone_name , ( zone : Time . Zone . t ) ) = add ( " roundtrip conversion " ^ zone_name ) ( fun ( ) -> let tm = random_tm state in let unix_time = 1664476678 . 000 in let time = Time . of_span_since_epoch ( Time . Span . of_sec unix_time ) in let ( zone_date , zone_ofday ) = let date , ofday = Time . to_date_ofday ~ zone ( : force Time . Zone . local ) time in Time . convert ~ from_tz ( : force Time . Zone . local ) ~ to_tz : zone date ofday in let round_trip_time = let round_date , round_ofday = Time . convert ~ from_tz : zone ~ to_tz ( : force Time . Zone . local ) zone_date zone_ofday in Time . of_date_ofday ~ zone ( : force Time . Zone . local ) round_date round_ofday in " time " @? ( if time = round_trip_time then true else begin failwith ( String . concat [ sprintf " tm : % s \ n " ( Sexp . to_string_hum ( Unix . sexp_of_tm tm ) ) ; sprintf " unix_time : . % 20f \ n " unix_time ; sprintf " our_time : . % 20f \ n " ( Time . to_span_since_epoch time |> Time . Span . to_sec ) ; sprintf " date , ofday : % s , % s \ n " ( Date . to_string zone_date ) ( Time . Ofday . to_string zone_ofday ) ; sprintf " round_trip : . % 20f \ n " ( Time . to_span_since_epoch round_trip_time |> Time . Span . to_sec ) ] ) end ) )
module Localtime_test_data = struct type t = { zone_name : string ; unix_time : float ; localtime_date_string : string ; localtime_ofday_string : string ; our_date_string : string ; our_ofday_string : string ; } [ @@ deriving sexp ] end
let add_random_localtime_tests state = List . iter ( Time . Zone . initialized_zones ( ) ) ~ f ( : fun ( zone_name , zone ) -> add ( " localtime " ^ zone_name ) ( fun ( ) -> let tm = random_tm state in let tm = Unix . gmtime ( Unix . timegm tm ) in Unix . putenv ~ key " : TZ " ~ data : zone_name ; ignore ( Unix . localtime 1000 . ) ; let unix_time , _ = Unix . mktime tm in let localtime = Unix . localtime unix_time in let localtime_date_string = Unix . strftime localtime " % Y -% m -% d " in let localtime_ofday_string = Unix . strftime localtime " % H :% M :% S . 000000 " in Unix . unsetenv ( " TZ " ) ; ignore ( Unix . localtime 1000 . ) ; let our_date , our_ofday = Time . to_date_ofday ( Time . of_span_since_epoch ( Time . Span . of_sec unix_time ) ) ~ zone in let test_data = { Localtime_test_data . zone_name ; unix_time ; our_date_string = Date . to_string our_date ; our_ofday_string = Time . Ofday . to_string our_ofday ; localtime_date_string ; localtime_ofday_string ; } in " date " @? ( if Localtime_test_data . ( test_data . localtime_date_string = test_data . our_date_string ) then true else failwith ( Sexp . to_string ( Localtime_test_data . sexp_of_t test_data ) ) ) ; " ofday " @? ( if Localtime_test_data . ( test_data . localtime_ofday_string = test_data . our_ofday_string ) then true else failwith ( Sexp . to_string ( Localtime_test_data . sexp_of_t test_data ) ) ) ) ) ; ;
let add_roundtrip_conversion_tests state = List . iter ( Time . Zone . initialized_zones ( ) ) ~ f ( : add_roundtrip_conversion_test state ) ; ;
let add_randomized_tests ( ) = let state = Random . State . make [ | 1 ; 2 ; 3 ; 4 ] | in add_random_string_round_trip_tests state ; add_random_localtime_tests state ; add_roundtrip_conversion_tests state ; ;
let ( ) = add_randomized_tests ( ) ; ; ;
let test = " zone " >::: ! zone_tests
type zenv = { env : Deftypes . tentry Env . t ; ren : Zident . t Env . t ; size : int }
let zempty = { env = Env . empty ; ren = Env . empty ; size = 0 }
let zero_from_env env = let select key { t_sort = s } = match s with | Smem { m_kind = Some ( Zero ) } -> true | _ -> false in Env . partition select env
let vars_of_env vars env = List . filter ( fun { vardec_name = x } -> Env . mem x env ) vars
let make env2 env1 = let one key _ ( l , acc ) = match l with | [ ] -> assert false | ( key ' , _ ) :: l -> l , Env . add key key ' acc in let l1 = Env . bindings env1 in let _ , ren = Env . fold one env2 ( l1 , Env . empty ) in ren
let compose r2_by_1 r2 = Env . map ( fun n2 -> try Env . find n2 r2_by_1 with Not_found -> assert false ) r2
let parallel { env = env1 ; ren = r1 ; size = s1 } { env = env2 ; ren = r2 ; size = s2 } = { env = Env . append env1 env2 ; ren = Env . append r1 r2 ; size = s1 + s2 }
let sharp { env = env1 ; ren = r1 ; size = s1 } { env = env2 ; ren = r2 ; size = s2 } = if s1 >= s2 then let r2_by_1 = make env2 env1 in let r = Env . append r1 ( Env . append r2_by_1 ( compose r2_by_1 r2 ) ) in { env = env1 ; ren = r ; size = s1 } else let r1_by_2 = make env1 env2 in let r = Env . append r2 ( Env . append r1_by_2 ( compose r1_by_2 r1 ) ) in { env = env2 ; ren = r ; size = s2 }
let rec equation ( { eq_desc = desc } as eq ) = match desc with | EQeq _ | EQpluseq _ | EQder _ | EQinit _ -> eq , zempty | EQmatch ( total , e , m_h_list ) -> let m_h_list , zenv = Zmisc . map_fold ( fun acc ( { m_body = b } as m_h ) -> { eq with eq_desc = EQmatch ( total , e , m_h_list ) } , zenv | EQreset ( eq_list , e ) -> let eq_list , zenv = equation_list eq_list in { eq with eq_desc = EQreset ( eq_list , e ) } , zenv | EQand ( and_eq_list ) -> let and_eq_list , zenv = equation_list and_eq_list in { eq with eq_desc = EQand ( and_eq_list ) } , zenv | EQbefore ( before_eq_list ) -> let before_eq_list , zenv = equation_list before_eq_list in { eq with eq_desc = EQbefore ( before_eq_list ) } , zenv | EQforall _ -> eq , zempty | EQblock _ | EQpresent _ | EQautomaton _ | EQnext _ | EQemit _ -> Zmisc . map_fold ( fun acc eq -> let eq , zenv = equation eq in let zero_env , b_env = zero_from_env b_env in let eq_list , zenv = equation_list eq_list in { b with b_vars = vars_of_env vars b_env ; b_env = b_env ; b_body = eq_list } , parallel { env = zero_env ; ren = Env . empty ; size = Env . cardinal zero_env } zenv
let rec rename_expression ren ( { e_desc = desc } as e ) = match desc with | Econst _ | Econstr0 _ | Eglobal _ -> e | Elocal ( x ) -> { e with e_desc = Elocal ( apply x ren ) } | Elast ( x ) -> { e with e_desc = Elast ( apply x ren ) } | Etuple ( e_list ) -> { e with e_desc = Etuple ( List . map ( rename_expression ren ) e_list ) } | Econstr1 ( c , e_list ) -> { e with e_desc = Econstr1 ( c , List . map ( rename_expression ren ) e_list ) } | Erecord ( n_e_list ) -> { e with e_desc = | Erecord_access ( e_record , ln ) -> { e with e_desc = Erecord_access ( rename_expression ren e_record , ln ) } | Erecord_with ( e_record , n_e_list ) -> { e with e_desc = | Eop ( op , e_list ) -> { e with e_desc = Eop ( op , List . map ( rename_expression ren ) e_list ) } | Eapp ( app , e_op , e_list ) -> let e_op = rename_expression ren e_op in let e_list = List . map ( rename_expression ren ) e_list in { e with e_desc = Eapp ( app , e_op , e_list ) } | Etypeconstraint ( e1 , ty ) -> { e with e_desc = Etypeconstraint ( rename_expression ren e1 , ty ) } | Eseq ( e1 , e2 ) -> { e with e_desc = Eseq ( rename_expression ren e1 , rename_expression ren e2 ) } | Eperiod _ | Epresent _ | Ematch _ | Elet _ | Eblock _ -> assert false let eq_list = rename_equation_list ren eq_list in { l with l_eq = eq_list } let desc = match desc with | EQeq ( { p_desc = Evarpat ( x ) } as p , e ) -> EQeq ( { p with p_desc = Evarpat ( apply x ren ) } , rename_expression ren e ) | EQeq ( p , e ) -> EQeq ( p , rename_expression ren e ) | EQpluseq ( x , e ) -> EQpluseq ( apply x ren , rename_expression ren e ) | EQinit ( x , e0 ) -> EQinit ( apply x ren , rename_expression ren e0 ) | EQmatch ( total , e , m_h_list ) -> let m_h_list = EQmatch ( total , rename_expression ren e , m_h_list ) | EQder ( x , e , None , [ ] ) -> EQder ( x , rename_expression ren e , None , [ ] ) | EQreset ( res_eq_list , e ) -> let e = rename_expression ren e in let res_eq_list = rename_equation_list ren res_eq_list in EQreset ( res_eq_list , e ) | EQand ( and_eq_list ) -> EQand ( rename_equation_list ren and_eq_list ) | EQbefore ( before_eq_list ) -> EQbefore ( rename_equation_list ren before_eq_list ) | EQforall ( { for_index = i_list ; for_init = init_list ; let index ( { desc = desc } as ind ) = let init ( { desc = desc } as ini ) = let i_list = List . map index i_list in let init_list = List . map init init_list in let b_eq_list = rename_block ren b_eq_list in EQforall { body with for_index = i_list ; for_init = init_list ; | EQblock _ | EQautomaton _ | EQpresent _ | EQemit _ | EQder _ | EQnext _ -> assert false in { eq with eq_desc = desc } let eq_list = rename_equation_list ren eq_list in { b with b_body = eq_list } try Env . find x ren with | Not_found -> x
let local ( { l_eq = eq_list ; l_env = l_env } as l ) = let eq_list , { env = env ; ren = ren } = equation_list eq_list in let eq_list = rename_equation_list ren eq_list in { l with l_eq = eq_list ; l_env = Env . append env l_env }
let expression ( { e_desc = desc } as e ) = let desc = match desc with | Elet ( l , e ) -> Elet ( local l , e ) | _ -> desc in { e with e_desc = desc }
let implementation impl = match impl . desc with | Econstdecl ( n , is_static , e ) -> { impl with desc = Econstdecl ( n , is_static , expression e ) } | Efundecl ( n , ( { f_body = e } as body ) ) -> { impl with desc = Efundecl ( n , { body with f_body = expression e } ) } | _ -> impl
let implementation_list impl_list = Zmisc . iter implementation impl_list
type kind = | S | AS | A | C | AD | D | P
type qualident = { qual : name ; id : name }
type longname = | Name of name | Modname of qualident
type ' a localized = { desc : ' a ; loc : Zlocation . location }
type type_expression = type_expression_desc localized | Etypevar of name | Etypeconstr of longname * type_expression list | Etypetuple of type_expression list | Etypevec of type_expression * size | Etypefun of kind * string option * type_expression * type_expression | Sconst of int | Sname of longname | Sop of size_op * size * size
type interface = interface_desc localized | Einter_open of name | Einter_typedecl of name * name list * type_decl | Einter_constdecl of name * type_expression | Eabstract_type | Eabbrev of type_expression | Evariant_type of constr_decl list | Erecord_type of ( name * type_expression ) list | Econstr0decl of name | Econstr1decl of name * type_expression list | Eopen of name | Etypedecl of name * name list * type_decl | Econstdecl of name * is_static * exp | Efundecl of name * funexp { f_kind : kind ; f_atomic : is_atomic ; f_args : pattern list ; f_body : exp ; f_loc : location } | Evar of longname | Econst of immediate | Econstr0 of constr | Econstr1 of constr * exp list | Elast of name | Eapp of app * exp * exp list | Eop of op * exp list | Etuple of exp list | Erecord_access of exp * longname | Erecord of ( longname * exp ) list | Erecord_with of exp * ( longname * exp ) list | Etypeconstraint of exp * type_expression | Elet of is_rec * eq list * exp | Eseq of exp * exp | Eperiod of period | Ematch of exp * exp match_handler list | Epresent of exp present_handler list * exp default option | Eautomaton of exp state_handler list * state_exp option | Ereset of exp * exp | Eblock of eq list block * exp | Init of ' a | Default of ' a | Efby | Eunarypre | Eifthenelse | Eminusgreater | Eup | Einitial | Edisc | Etest | Eaccess | Eupdate | Eslice of size * size | Econcat | Eatomic | Eint of int | Efloat of float | Ebool of bool | Echar of char | Estring of string | Evoid | Cimmediate of immediate | Cglobal of longname { p_phase : exp option ; p_period : exp } | Etuplepat of pattern list | Evarpat of name | Ewildpat | Econstpat of immediate | Econstr0pat of longname | Econstr1pat of longname * pattern list | Ealiaspat of pattern * name | Eorpat of pattern * pattern | Erecordpat of ( longname * pattern ) list | Etypeconstraintpat of pattern * type_expression | EQeq of pattern * exp | EQder of name * exp * exp option * exp present_handler list | EQinit of name * exp | EQnext of name * exp * exp option | EQemit of name * exp option | EQpluseq of name * exp | EQautomaton of eq list state_handler list * state_exp option | EQpresent of eq list block present_handler list * eq list block option | EQmatch of exp * eq list block match_handler list | EQifthenelse of exp * eq list block * eq list block option | EQreset of eq list * exp | EQand of eq list | EQbefore of eq list | EQblock of eq list block | EQforall of forall_handler { b_vars : vardec list ; b_locals : local list ; b_body : ' a } { vardec_name : name ; vardec_default : constant default option ; vardec_combine : longname option ; } | Estate0pat of name | Estate1pat of name * name list | Estate0 of name | Estate1 of name * exp list { e_cond : scondpat ; e_reset : bool ; e_block : eq list block option ; e_next_state : state_exp ; } | Econdand of scondpat * scondpat | Econdor of scondpat * scondpat | Econdexp of exp | Econdon of scondpat * exp | Econdpat of exp * pattern { m_pat : pattern ; m_body : ' a ; } { p_cond : scondpat ; p_body : ' a ; } { s_state : statepat ; s_block : ' a block ; s_until : escape list ; s_unless : escape list } { for_indexes : indexes_desc localized list ; for_init : init_desc localized list ; for_body : eq list block } | Einput of name * exp | Eoutput of name * name | Eindex of name * exp * exp | Einit_last of name * exp
let remove_trailing_null s = let n = String . length s in let i = ref ( n - 1 ) in while ! i >= 0 && s . [ ! i ] = ' \ 000 ' do i := ! i - 1 done ; String . sub s 0 ( ! i + 1 )
let serialize z = let n = if Z . ( lt z zero ) then Z . ( neg ( add ( add z z ) one ) ) else Z . ( add z z ) in n |> Z . to_bits |> remove_trailing_null
let deserialize z = let n = Z . of_bits z in let z = Z . shift_right_trunc n 1 in if Z . ( n land one = zero ) then z else Z . neg z
let leq a b = Z . compare a b <= 0
let geq a b = Z . compare a b >= 0
let lt a b = Z . compare a b < 0
let gt a b = Z . compare a b > 0
let ( < ) = lt
let ( > ) = gt
let ( <= ) = leq
let ( >= ) = geq
let invert a n = try Some ( Z . invert a n ) with Division_by_zero -> None
let pr ch x = output_string ch ( I . to_string x ) ; flush ch
let pr2 ch ( x , y ) = Printf . fprintf ch " % s , % s " ( I . to_string x ) ( I . to_string y ) ; flush ch
let pr3 ch ( x , y , z ) = Printf . fprintf ch " % s , % s , % s " ( I . to_string x ) ( I . to_string y ) ( I . to_string z ) ; flush ch
let prfloat ch ( x , y : float * float ) = if x = y then Printf . fprintf ch " OK " else Printf . fprintf ch " WRONG ! ( expected % g , got % g ) " y x
let prmarshal ch ( x , y : I . t * I . t ) = ( if I . equal x y then Printf . fprintf ch " OK " else Printf . fprintf ch " WRONG ! ( expected % a , got % a ) " pr y pr x ) ; flush ch
let pow2 n = let rec doit acc n = if n <= 0 then acc else doit ( I . add acc acc ) ( n - 1 ) in doit I . one n
let fact n = let rec doit acc n = if n <= 1 then acc else doit ( I . mul acc ( I . of_int n ) ) ( n - 1 ) in doit I . one n
let pow a b = let rec doit b = if b <= 0 then I . one else let acc = doit ( b lsr 1 ) in if b land 1 = 1 then I . mul ( I . mul acc acc ) ( I . of_int a ) else I . mul acc acc in doit b
let cvt_int x = try string_of_int ( I . to_int x ) with I . Overflow -> " ovf "
let cvt_int32 x = try Int32 . to_string ( I . to_int32 x ) with I . Overflow -> " ovf "
let cvt_int64 x = try Int64 . to_string ( I . to_int64 x ) with I . Overflow -> " ovf "
let cvt_nativeint x = try Nativeint . to_string ( I . to_nativeint x ) with I . Overflow -> " ovf "
let p2 = I . of_int 2
let p30 = pow2 30
let p62 = pow2 62
let p300 = pow2 300
let p120 = pow2 120
let p121 = pow2 121
let maxi = I . of_int max_int
let mini = I . of_int min_int
let maxi32 = I . of_int32 Int32 . max_int
let mini32 = I . of_int32 Int32 . min_int
let maxi64 = I . of_int64 Int64 . max_int
let mini64 = I . of_int64 Int64 . min_int
let maxni = I . of_nativeint Nativeint . max_int
let minni = I . of_nativeint Nativeint . min_int
let chk_bits x = Printf . printf " to_bits % a \ n " = pr x ; String . iter ( fun c -> Printf . printf " % 02x " ( Char . code c ) ) ( I . to_bits x ) ; Printf . printf " \ n " ; assert ( I . equal ( I . abs x ) ( I . of_bits ( I . to_bits x ) ) ) ; assert ( ( I . to_bits x ) = ( I . to_bits ( I . neg x ) ) ) ; Printf . printf " marshal round trip % a \ n " = pr x ; let y = Marshal . ( from_string ( to_string x [ ] ) 0 ) in Printf . printf " % a \ n " prmarshal ( y , x )
let chk_extract ( x , o , l ) = let expected = I . logand ( I . shift_right x o ) ( I . pred ( I . shift_left ( I . of_int 1 ) l ) ) and actual = I . extract x o l in Printf . printf " extract % a % d % d = % a " pr x o l pr actual ; if I . equal actual expected then Printf . printf " ( passed ) \ n " else Printf . printf " ( FAILED , expected % a ) \ n " pr expected
let chk_signed_extract ( x , o , l ) = let uns_res = I . extract x o l in let expected = if I . compare uns_res ( I . shift_left ( I . of_int 1 ) ( l - 1 ) ) >= 0 then I . sub uns_res ( I . shift_left ( I . of_int 1 ) l ) else uns_res in let actual = I . signed_extract x o l in Printf . printf " signed_extract % a % d % d = % a " pr x o l pr actual ; if I . equal actual expected then Printf . printf " ( passed ) \ n " else Printf . printf " ( FAILED , expected % a ) \ n " pr expected
let chk_numbits_tz x = Printf . printf " numbits / trailing_zeros % a " pr x ; let n = I . numbits x and z = I . trailing_zeros x in if if I . equal x I . zero then n = 0 && z = max_int else n > 0 && z >= 0 && z < n && I . leq ( I . shift_left I . one ( n - 1 ) ) ( I . abs x ) && I . lt ( I . abs x ) ( I . shift_left I . one n ) && ( z = 0 || I . equal ( I . extract x 0 z ) I . zero ) && I . testbit x z then Printf . printf " ( passed ) \ n " else Printf . printf " ( FAILED ) \ n "
let chk_testbit x = Printf . printf " testbit % a " pr x ; let n = I . numbits x in let ok = ref true in for i = 0 to n + 64 do let actual = I . testbit x i and expected = I . extract x i 1 in if not ( I . equal expected ( if actual then I . one else I . zero ) ) then begin Printf . printf " ( error on % d ) " i ; ok := false end done ; if ! ok then Printf . printf " ( passed ) \ n " else Printf . printf " ( FAILED ) \ n "
let test_Z ( ) = Printf . printf " 0 \ n = % a \ n " pr I . zero ; Printf . printf " 1 \ n = % a \ n " pr I . one ; Printf . printf " - 1 \ n = % a \ n " pr I . minus_one ; Printf . printf " 42 \ n = % a \ n " pr ( I . of_int 42 ) ; Printf . printf " 1 + 1 \ n = % a \ n " pr ( I . add I . one I . one ) ; Printf . printf " 1 - 1 \ n = % a \ n " pr ( I . sub I . one I . one ) ; Printf . printf " - 1 \ n = % a \ n " pr ( I . neg I . one ) ; Printf . printf " 0 - 1 \ n = % a \ n " pr ( I . sub I . zero I . one ) ; Printf . printf " max_int \ n = % a \ n " pr maxi ; Printf . printf " min_int \ n = % a \ n " pr mini ; Printf . printf " - max_int \ n = % a \ n " pr ( I . neg maxi ) ; Printf . printf " - min_int \ n = % a \ n " pr ( I . neg mini ) ; Printf . printf " 2 ^ 300 \ n = % a \ n " pr p300 ; Printf . printf " 2 ^ 120 \ n = % a \ n " pr p120 ; Printf . printf " 2 ^ 300 + 2 ^ 120 \ n = % a \ n " pr ( I . add p300 p120 ) ; Printf . printf " 2 ^ 300 - 2 ^ 120 \ n = % a \ n " pr ( I . sub p300 p120 ) ; Printf . printf " 2 ^ 300 ( ( +- 2 ^ 120 ) ) \ n = % a \ n " pr ( I . add p300 ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 - 2 ^ 300 \ n = % a \ n " pr ( I . sub p120 p300 ) ; Printf . printf " 2 ^ 120 ( ( +- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . add p120 ( I . neg p300 ) ) ; Printf . printf " ( - 2 ^ 120 ) ( ( +- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . add ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " ( - 2 ^ 120 ) - 2 ^ 300 \ n = % a \ n " pr ( I . sub ( I . neg p120 ) p300 ) ; Printf . printf " 2 ^ 300 - 2 ^ 300 \ n = % a \ n " pr ( I . sub p300 p300 ) ; Printf . printf " 2 ^ 121 \ n = % a \ n " pr p121 ; Printf . printf " 2 ^ 121 + 2 ^ 120 \ n = % a \ n " pr ( I . add p121 p120 ) ; Printf . printf " 2 ^ 121 - 2 ^ 120 \ n = % a \ n " pr ( I . sub p121 p120 ) ; Printf . printf " 2 ^ 121 ( ( +- 2 ^ 120 ) ) \ n = % a \ n " pr ( I . add p121 ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 - 2 ^ 121 \ n = % a \ n " pr ( I . sub p120 p121 ) ; Printf . printf " 2 ^ 120 ( ( +- 2 ^ 121 ) ) \ n = % a \ n " pr ( I . add p120 ( I . neg p121 ) ) ; Printf . printf " ( - 2 ^ 120 ) ( ( +- 2 ^ 121 ) ) \ n = % a \ n " pr ( I . add ( I . neg p120 ) ( I . neg p121 ) ) ; Printf . printf " ( - 2 ^ 120 ) - 2 ^ 121 \ n = % a \ n " pr ( I . sub ( I . neg p120 ) p121 ) ; Printf . printf " 2 ^ 121 + 0 \ n = % a \ n " pr ( I . add p121 I . zero ) ; Printf . printf " 2 ^ 121 - 0 \ n = % a \ n " pr ( I . sub p121 I . zero ) ; Printf . printf " 0 + 2 ^ 121 \ n = % a \ n " pr ( I . add I . zero p121 ) ; Printf . printf " 0 - 2 ^ 121 \ n = % a \ n " pr ( I . sub I . zero p121 ) ; Printf . printf " 2 ^ 300 + 1 \ n = % a \ n " pr ( I . add p300 I . one ) ; Printf . printf " 2 ^ 300 - 1 \ n = % a \ n " pr ( I . sub p300 I . one ) ; Printf . printf " 1 + 2 ^ 300 \ n = % a \ n " pr ( I . add I . one p300 ) ; Printf . printf " 1 - 2 ^ 300 \ n = % a \ n " pr ( I . sub I . one p300 ) ; Printf . printf " 2 ^ 300 ( +- 1 ) \ n = % a \ n " pr ( I . add p300 I . minus_one ) ; Printf . printf " 2 ^ 300 ( -- 1 ) \ n = % a \ n " pr ( I . sub p300 I . minus_one ) ; Printf . printf " ( - 1 ) + 2 ^ 300 \ n = % a \ n " pr ( I . add I . minus_one p300 ) ; Printf . printf " ( - 1 ) - 2 ^ 300 \ n = % a \ n " pr ( I . sub I . minus_one p300 ) ; Printf . printf " ( - 2 ^ 300 ) + 1 \ n = % a \ n " pr ( I . add ( I . neg p300 ) I . one ) ; Printf . printf " ( - 2 ^ 300 ) - 1 \ n = % a \ n " pr ( I . sub ( I . neg p300 ) I . one ) ; Printf . printf " 1 ( ( +- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . add I . one ( I . neg p300 ) ) ; Printf . printf " 1 ( ( -- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . sub I . one ( I . neg p300 ) ) ; Printf . printf " ( - 2 ^ 300 ) ( +- 1 ) \ n = % a \ n " pr ( I . add ( I . neg p300 ) I . minus_one ) ; Printf . printf " ( - 2 ^ 300 ) ( -- 1 ) \ n = % a \ n " pr ( I . sub ( I . neg p300 ) I . minus_one ) ; Printf . printf " ( - 1 ) ( ( +- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . add I . minus_one ( I . neg p300 ) ) ; Printf . printf " ( - 1 ) ( ( -- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . sub I . minus_one ( I . neg p300 ) ) ; Printf . printf " max_int + 1 \ n = % a \ n " pr ( I . add maxi I . one ) ; Printf . printf " min_int - 1 \ n = % a \ n " pr ( I . sub mini I . one ) ; Printf . printf " - max_int - 1 \ n = % a \ n " pr ( I . sub ( I . neg maxi ) I . one ) ; Printf . printf " - min_int - 1 \ n = % a \ n " pr ( I . sub ( I . neg mini ) I . one ) ; Printf . printf " 5 ! = % a \ n " pr ( fact 5 ) ; Printf . printf " 12 ! = % a \ n " pr ( fact 12 ) ; Printf . printf " 15 ! = % a \ n " pr ( fact 15 ) ; Printf . printf " 20 ! = % a \ n " pr ( fact 20 ) ; Printf . printf " 25 ! = % a \ n " pr ( fact 25 ) ; Printf . printf " 50 ! = % a \ n " pr ( fact 50 ) ; Printf . printf " 2 ^ 300 * 2 ^ 120 \ n = % a \ n " pr ( I . mul p300 p120 ) ; Printf . printf " 2 ^ 120 * 2 ^ 300 \ n = % a \ n " pr ( I . mul p120 p300 ) ; Printf . printf " 2 ^ 300 ( ( *- 2 ^ 120 ) ) \ n = % a \ n " pr ( I . mul p300 ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 ( ( *- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . mul p120 ( I . neg p300 ) ) ; Printf . printf " ( - 2 ^ 120 ) ( ( *- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . mul ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " 2 ^ 121 * 2 ^ 120 \ n = % a \ n " pr ( I . mul p121 p120 ) ; Printf . printf " 2 ^ 120 * 2 ^ 121 \ n = % a \ n " pr ( I . mul p120 p121 ) ; Printf . printf " 2 ^ 121 * 0 \ n = % a \ n " pr ( I . mul p121 I . zero ) ; Printf . printf " 0 * 2 ^ 121 \ n = % a \ n " pr ( I . mul I . zero p121 ) ; Printf . printf " 2 ^ 300 * 1 \ n = % a \ n " pr ( I . mul p300 I . one ) ; Printf . printf " 1 * 2 ^ 300 \ n = % a \ n " pr ( I . mul I . one p300 ) ; Printf . printf " 2 ^ 300 ( *- 1 ) \ n = % a \ n " pr ( I . mul p300 I . minus_one ) ; Printf . printf " ( - 1 ) * 2 ^ 300 \ n = % a \ n " pr ( I . mul I . minus_one p300 ) ; Printf . printf " ( - 2 ^ 300 ) * 1 \ n = % a \ n " pr ( I . mul ( I . neg p300 ) I . one ) ; Printf . printf " 1 ( ( *- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . mul I . one ( I . neg p300 ) ) ; Printf . printf " ( - 2 ^ 300 ) ( *- 1 ) \ n = % a \ n " pr ( I . mul ( I . neg p300 ) I . minus_one ) ; Printf . printf " ( - 1 ) ( ( *- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . mul I . minus_one ( I . neg p300 ) ) ; Printf . printf " 1 ( * 2 ^ 30 ) \ n = % a \ n " pr ( I . mul I . one p30 ) ; Printf . printf " 1 ( * 2 ^ 62 ) \ n = % a \ n " pr ( I . mul I . one p62 ) ; Printf . printf " ( 2 ^ 30 ) ( * 2 ^ 30 ) \ n = % a \ n " pr ( I . mul p30 p30 ) ; Printf . printf " ( 2 ^ 62 ) ( * 2 ^ 62 ) \ n = % a \ n " pr ( I . mul p62 p62 ) ; Printf . printf " 0 + 1 \ n = % a \ n " pr ( I . succ I . zero ) ; Printf . printf " 1 + 1 \ n = % a \ n " pr ( I . succ I . one ) ; Printf . printf " - 1 + 1 \ n = % a \ n " pr ( I . succ I . minus_one ) ; Printf . printf " 2 + 1 \ n = % a \ n " pr ( I . succ p2 ) ; Printf . printf " - 2 + 1 \ n = % a \ n " pr ( I . succ ( I . neg p2 ) ) ; Printf . printf " ( 2 ^ 300 ) + 1 \ n = % a \ n " pr ( I . succ p300 ) ; Printf . printf " ( - 2 ^ 300 ) + 1 \ n = % a \ n " pr ( I . succ ( I . neg p300 ) ) ; Printf . printf " 0 - 1 \ n = % a \ n " pr ( I . pred I . zero ) ; Printf . printf " 1 - 1 \ n = % a \ n " pr ( I . pred I . one ) ; Printf . printf " - 1 - 1 \ n = % a \ n " pr ( I . pred I . minus_one ) ; Printf . printf " 2 - 1 \ n = % a \ n " pr ( I . pred p2 ) ; Printf . printf " - 2 - 1 \ n = % a \ n " pr ( I . pred ( I . neg p2 ) ) ; Printf . printf " ( 2 ^ 300 ) - 1 \ n = % a \ n " pr ( I . pred p300 ) ; Printf . printf " ( - 2 ^ 300 ) - 1 \ n = % a \ n " pr ( I . pred ( I . neg p300 ) ) ; Printf . printf " max_int + 1 \ n = % a \ n " pr ( I . succ maxi ) ; Printf . printf " min_int - 1 \ n = % a \ n " pr ( I . pred mini ) ; Printf . printf " - max_int - 1 \ n = % a \ n " pr ( I . pred ( I . neg maxi ) ) ; Printf . printf " - min_int - 1 \ n = % a \ n " pr ( I . pred ( I . neg mini ) ) ; Printf . printf " abs ( 0 ) \ n = % a \ n " pr ( I . abs I . zero ) ; Printf . printf " abs ( 1 ) \ n = % a \ n " pr ( I . abs I . one ) ; Printf . printf " abs ( - 1 ) \ n = % a \ n " pr ( I . abs I . minus_one ) ; Printf . printf " abs ( min_int ) \ n = % a \ n " pr ( I . abs mini ) ; Printf . printf " abs ( 2 ^ 300 ) \ n = % a \ n " pr ( I . abs p300 ) ; Printf . printf " abs ( ( - 2 ^ 300 ) ) \ n = % a \ n " pr ( I . abs ( I . neg p300 ) ) ; Printf . printf " max_natint \ n = % a \ n " pr maxni ; Printf . printf " max_int32 \ n = % a \ n " pr maxi32 ; Printf . printf " max_int64 \ n = % a \ n " pr maxi64 ; Printf . printf " to_int 1 \ n = % s \ n " ( cvt_int I . one ) ; Printf . printf " to_int max_int \ n = % s \ n " ( cvt_int maxi ) ; Printf . printf " to_int max_natint \ n = % s \ n " ( cvt_int maxni ) ; Printf . printf " to_int max_int32 \ n = % s \ n " ( cvt_int maxi32 ) ; Printf . printf " to_int max_int64 \ n = % s \ n " ( cvt_int maxi64 ) ; Printf . printf " to_int32 1 \ n = % s \ n " ( cvt_int32 I . one ) ; Printf . printf " to_int32 max_int \ n = % s \ n " ( cvt_int32 maxi ) ; Printf . printf " to_int32 max_natint \ n = % s \ n " ( cvt_int32 maxni ) ; Printf . printf " to_int32 max_int32 \ n = % s \ n " ( cvt_int32 maxi32 ) ; Printf . printf " to_int32 max_int64 \ n = % s \ n " ( cvt_int32 maxi64 ) ; Printf . printf " to_int64 1 \ n = % s \ n " ( cvt_int64 I . one ) ; Printf . printf " to_int64 max_int \ n = % s \ n " ( cvt_int64 maxi ) ; Printf . printf " to_int64 max_natint \ n = % s \ n " ( cvt_int64 maxni ) ; Printf . printf " to_int64 max_int32 \ n = % s \ n " ( cvt_int64 maxi32 ) ; Printf . printf " to_int64 max_int64 \ n = % s \ n " ( cvt_int64 maxi64 ) ; Printf . printf " to_natint 1 \ n = % s \ n " ( cvt_nativeint I . one ) ; Printf . printf " to_natint max_int \ n = % s \ n " ( cvt_nativeint maxi ) ; Printf . printf " to_natint max_natint \ n = % s \ n " ( cvt_nativeint maxni ) ; Printf . printf " to_natint max_int32 \ n = % s \ n " ( cvt_nativeint maxi32 ) ; Printf . printf " to_natint max_int64 \ n = % s \ n " ( cvt_nativeint maxi64 ) ; Printf . printf " to_int - min_int \ n = % s \ n " ( cvt_int ( I . neg mini ) ) ; Printf . printf " to_int - min_natint \ n = % s \ n " ( cvt_int ( I . neg minni ) ) ; Printf . printf " to_int - min_int32 \ n = % s \ n " ( cvt_int ( I . neg mini32 ) ) ; Printf . printf " to_int - min_int64 \ n = % s \ n " ( cvt_int ( I . neg mini64 ) ) ; Printf . printf " to_int32 - min_int \ n = % s \ n " ( cvt_int32 ( I . neg mini ) ) ; Printf . printf " to_int32 - min_natint \ n = % s \ n " ( cvt_int32 ( I . neg minni ) ) ; Printf . printf " to_int32 - min_int32 \ n = % s \ n " ( cvt_int32 ( I . neg mini32 ) ) ; Printf . printf " to_int32 - min_int64 \ n = % s \ n " ( cvt_int32 ( I . neg mini64 ) ) ; Printf . printf " to_int64 - min_int \ n = % s \ n " ( cvt_int64 ( I . neg mini ) ) ; Printf . printf " to_int64 - min_natint \ n = % s \ n " ( cvt_int64 ( I . neg minni ) ) ; Printf . printf " to_int64 - min_int32 \ n = % s \ n " ( cvt_int64 ( I . neg mini32 ) ) ; Printf . printf " to_int64 - min_int64 \ n = % s \ n " ( cvt_int64 ( I . neg mini64 ) ) ; Printf . printf " to_natint - min_int \ n = % s \ n " ( cvt_nativeint ( I . neg mini ) ) ; Printf . printf " to_natint - min_natint \ n = % s \ n " ( cvt_nativeint ( I . neg minni ) ) ; Printf . printf " to_natint - min_int32 \ n = % s \ n " ( cvt_nativeint ( I . neg mini32 ) ) ; Printf . printf " to_natint - min_int64 \ n = % s \ n " ( cvt_nativeint ( I . neg mini64 ) ) ; Printf . printf " of_float 1 . \ n = % a \ n " pr ( I . of_float 1 . ) ; Printf . printf " of_float - 1 . \ n = % a \ n " pr ( I . of_float ( . - 1 . ) ) ; Printf . printf " of_float pi \ n = % a \ n " pr ( I . of_float ( 2 . . * acos 0 . ) ) ; Printf . printf " of_float 2 ^ 30 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 30 ) ) ; Printf . printf " of_float 2 ^ 31 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 31 ) ) ; Printf . printf " of_float 2 ^ 32 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 32 ) ) ; Printf . printf " of_float 2 ^ 33 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 33 ) ) ; Printf . printf " of_float - 2 ^ 30 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 30 ) ) ) ; Printf . printf " of_float - 2 ^ 31 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 31 ) ) ) ; Printf . printf " of_float - 2 ^ 32 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 32 ) ) ) ; Printf . printf " of_float - 2 ^ 33 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 33 ) ) ) ; Printf . printf " of_float 2 ^ 61 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 61 ) ) ; Printf . printf " of_float 2 ^ 62 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 62 ) ) ; Printf . printf " of_float 2 ^ 63 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 63 ) ) ; Printf . printf " of_float 2 ^ 64 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 64 ) ) ; Printf . printf " of_float 2 ^ 65 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 65 ) ) ; Printf . printf " of_float - 2 ^ 61 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 61 ) ) ) ; Printf . printf " of_float - 2 ^ 62 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 62 ) ) ) ; Printf . printf " of_float - 2 ^ 63 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 63 ) ) ) ; Printf . printf " of_float - 2 ^ 64 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 64 ) ) ) ; Printf . printf " of_float - 2 ^ 65 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 65 ) ) ) ; Printf . printf " of_float 2 ^ 120 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 120 ) ) ; Printf . printf " of_float 2 ^ 300 \ n = % a \ n " pr ( I . of_float ( ldexp 1 . 300 ) ) ; Printf . printf " of_float - 2 ^ 120 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 120 ) ) ) ; Printf . printf " of_float - 2 ^ 300 \ n = % a \ n " pr ( I . of_float ( . ( - ldexp 1 . 300 ) ) ) ; Printf . printf " of_float 0 . 5 \ n = % a \ n " pr ( I . of_float 0 . 5 ) ; Printf . printf " of_float - 0 . 5 \ n = % a \ n " pr ( I . of_float ( . - 0 . 5 ) ) ; Printf . printf " of_float 200 . 5 \ n = % a \ n " pr ( I . of_float 200 . 5 ) ; Printf . printf " of_float - 200 . 5 \ n = % a \ n " pr ( I . of_float ( . - 200 . 5 ) ) ; Printf . printf " to_float 0 \ n = % a \ n " prfloat ( I . to_float I . zero , 0 . 0 ) ; Printf . printf " to_float 1 \ n = % a \ n " prfloat ( I . to_float I . one , 1 . 0 ) ; Printf . printf " to_float - 1 \ n = % a \ n " prfloat ( I . to_float I . minus_one , - 1 . 0 ) ; Printf . printf " to_float 2 ^ 120 \ n = % a \ n " prfloat ( I . to_float p120 , ldexp 1 . 0 120 ) ; Printf . printf " to_float - 2 ^ 120 \ n = % a \ n " prfloat ( I . to_float ( I . neg p120 ) , . - ( ldexp 1 . 0 120 ) ) ; Printf . printf " to_float ( 2 ^ 120 - 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . pred p120 ) , ldexp 1 . 0 120 ) ; Printf . printf " to_float ( - 2 ^ 120 + 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . succ ( I . neg p120 ) ) , . - ( ldexp 1 . 0 120 ) ) ; Printf . printf " to_float 2 ^ 63 \ n = % a \ n " prfloat ( I . to_float ( pow2 63 ) , ldexp 1 . 0 63 ) ; Printf . printf " to_float - 2 ^ 63 \ n = % a \ n " prfloat ( I . to_float ( I . neg ( pow2 63 ) ) , . - ( ldexp 1 . 0 63 ) ) ; Printf . printf " to_float ( 2 ^ 63 - 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . pred ( pow2 63 ) ) , ldexp 1 . 0 63 ) ; Printf . printf " to_float ( - 2 ^ 63 - 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . pred ( I . neg ( pow2 63 ) ) ) , . - ( ldexp 1 . 0 63 ) ) ; Printf . printf " to_float ( - 2 ^ 63 + 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . succ ( I . neg ( pow2 63 ) ) ) , . - ( ldexp 1 . 0 63 ) ) ; Printf . printf " to_float 2 ^ 300 \ n = % a \ n " prfloat ( I . to_float p300 , ldexp 1 . 0 300 ) ; Printf . printf " to_float - 2 ^ 300 \ n = % a \ n " prfloat ( I . to_float ( I . neg p300 ) , . - ( ldexp 1 . 0 300 ) ) ; Printf . printf " to_float ( 2 ^ 300 - 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . pred p300 ) , ldexp 1 . 0 300 ) ; Printf . printf " to_float ( - 2 ^ 300 + 1 ) \ n = % a \ n " prfloat ( I . to_float ( I . succ ( I . neg p300 ) ) , . - ( ldexp 1 . 0 300 ) ) ; Printf . printf " of_string 12 \ n = % a \ n " pr ( I . of_string " 12 " ) ; Printf . printf " of_string 0x12 \ n = % a \ n " pr ( I . of_string " 0x12 " ) ; Printf . printf " of_string 0b10 \ n = % a \ n " pr ( I . of_string " 0b10 " ) ; Printf . printf " of_string 0o12 \ n = % a \ n " pr ( I . of_string " 0o12 " ) ; Printf . printf " of_string - 12 \ n = % a \ n " pr ( I . of_string " - 12 " ) ; Printf . printf " of_string - 0x12 \ n = % a \ n " pr ( I . of_string " - 0x12 " ) ; Printf . printf " of_string - 0b10 \ n = % a \ n " pr ( I . of_string " - 0b10 " ) ; Printf . printf " of_string - 0o12 \ n = % a \ n " pr ( I . of_string " - 0o12 " ) ; Printf . printf " of_string 000123456789012345678901234567890 \ n = % a \ n " pr ( I . of_string " 000123456789012345678901234567890 " ) ; Printf . printf " 2 ^ 120 / 2 ^ 300 ( trunc ) \ n = % a \ n " pr ( I . div p120 p300 ) ; Printf . printf " max_int / 2 ( trunc ) \ n = % a \ n " pr ( I . div maxi p2 ) ; Printf . printf " ( 2 ^ 300 + 1 ) / 2 ^ 120 ( trunc ) \ n = % a \ n " pr ( I . div ( I . succ p300 ) p120 ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) / 2 ^ 120 ( trunc ) \ n = % a \ n " pr ( I . div ( I . neg ( I . succ p300 ) ) p120 ) ; Printf . printf " ( 2 ^ 300 + 1 ) / ( ( - 2 ^ 120 ) ) ( trunc ) \ n = % a \ n " pr ( I . div ( I . succ p300 ) ( I . neg p120 ) ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) / ( ( - 2 ^ 120 ) ) ( trunc ) \ n = % a \ n " pr ( I . div ( I . neg ( I . succ p300 ) ) ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 / 2 ^ 300 ( ceil ) \ n = % a \ n " pr ( I . cdiv p120 p300 ) ; Printf . printf " max_int / 2 ( ceil ) \ n = % a \ n " pr ( I . cdiv maxi p2 ) ; Printf . printf " ( 2 ^ 300 + 1 ) / 2 ^ 120 ( ceil ) \ n = % a \ n " pr ( I . cdiv ( I . succ p300 ) p120 ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) / 2 ^ 120 ( ceil ) \ n = % a \ n " pr ( I . cdiv ( I . neg ( I . succ p300 ) ) p120 ) ; Printf . printf " ( 2 ^ 300 + 1 ) / ( ( - 2 ^ 120 ) ) ( ceil ) \ n = % a \ n " pr ( I . cdiv ( I . succ p300 ) ( I . neg p120 ) ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) / ( ( - 2 ^ 120 ) ) ( ceil ) \ n = % a \ n " pr ( I . cdiv ( I . neg ( I . succ p300 ) ) ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 / 2 ^ 300 ( floor ) \ n = % a \ n " pr ( I . fdiv p120 p300 ) ; Printf . printf " max_int / 2 ( floor ) \ n = % a \ n " pr ( I . fdiv maxi p2 ) ; Printf . printf " ( 2 ^ 300 + 1 ) / 2 ^ 120 ( floor ) \ n = % a \ n " pr ( I . fdiv ( I . succ p300 ) p120 ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) / 2 ^ 120 ( floor ) \ n = % a \ n " pr ( I . fdiv ( I . neg ( I . succ p300 ) ) p120 ) ; Printf . printf " ( 2 ^ 300 + 1 ) / ( ( - 2 ^ 120 ) ) ( floor ) \ n = % a \ n " pr ( I . fdiv ( I . succ p300 ) ( I . neg p120 ) ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) / ( ( - 2 ^ 120 ) ) ( floor ) \ n = % a \ n " pr ( I . fdiv ( I . neg ( I . succ p300 ) ) ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 %% 2 ^ 300 \ n = % a \ n " pr ( I . rem p120 p300 ) ; Printf . printf " max_int %% 2 \ n = % a \ n " pr ( I . rem maxi p2 ) ; Printf . printf " ( 2 ^ 300 + 1 ) %% 2 ^ 120 \ n = % a \ n " pr ( I . rem ( I . succ p300 ) p120 ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) %% 2 ^ 120 \ n = % a \ n " pr ( I . rem ( I . neg ( I . succ p300 ) ) p120 ) ; Printf . printf " ( 2 ^ 300 + 1 ) %% ( ( - 2 ^ 120 ) ) \ n = % a \ n " pr ( I . rem ( I . succ p300 ) ( I . neg p120 ) ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) %% ( ( - 2 ^ 120 ) ) \ n = % a \ n " pr ( I . rem ( I . neg ( I . succ p300 ) ) ( I . neg p120 ) ) ; Printf . printf " 2 ^ 120 , /%% 2 ^ 300 \ n = % a \ n " pr2 ( I . div_rem p120 p300 ) ; Printf . printf " max_int , /%% 2 \ n = % a \ n " pr2 ( I . div_rem maxi p2 ) ; Printf . printf " ( 2 ^ 300 + 1 ) , /%% 2 ^ 120 \ n = % a \ n " pr2 ( I . div_rem ( I . succ p300 ) p120 ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) , /%% 2 ^ 120 \ n = % a \ n " pr2 ( I . div_rem ( I . neg ( I . succ p300 ) ) p120 ) ; Printf . printf " ( 2 ^ 300 + 1 ) , /%% ( ( - 2 ^ 120 ) ) \ n = % a \ n " pr2 ( I . div_rem ( I . succ p300 ) ( I . neg p120 ) ) ; Printf . printf " ( ( - 2 ^ 300 + 1 ) ) , /%% ( ( - 2 ^ 120 ) ) \ n = % a \ n " pr2 ( I . div_rem ( I . neg ( I . succ p300 ) ) ( I . neg p120 ) ) ; Printf . printf " 1 & 2 \ n = % a \ n " pr ( I . logand I . one p2 ) ; Printf . printf " 1 & 2 ^ 300 \ n = % a \ n " pr ( I . logand I . one p300 ) ; Printf . printf " 2 ^ 120 & 2 ^ 300 \ n = % a \ n " pr ( I . logand p120 p300 ) ; Printf . printf " 2 ^ 300 & 2 ^ 120 \ n = % a \ n " pr ( I . logand p300 p120 ) ; Printf . printf " 2 ^ 300 & 2 ^ 300 \ n = % a \ n " pr ( I . logand p300 p300 ) ; Printf . printf " 2 ^ 300 & 0 \ n = % a \ n " pr ( I . logand p300 I . zero ) ; Printf . printf " - 2 ^ 120 & 2 ^ 300 \ n = % a \ n " pr ( I . logand ( I . neg p120 ) p300 ) ; Printf . printf " 2 ^ 120 & - 2 ^ 300 \ n = % a \ n " pr ( I . logand p120 ( I . neg p300 ) ) ; Printf . printf " - 2 ^ 120 & - 2 ^ 300 \ n = % a \ n " pr ( I . logand ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " - 2 ^ 300 & 2 ^ 120 \ n = % a \ n " pr ( I . logand ( I . neg p300 ) p120 ) ; Printf . printf " 2 ^ 300 & - 2 ^ 120 \ n = % a \ n " pr ( I . logand p300 ( I . neg p120 ) ) ; Printf . printf " - 2 ^ 300 & - 2 ^ 120 \ n = % a \ n " pr ( I . logand ( I . neg p300 ) ( I . neg p120 ) ) ; Printf . printf " 1 | 2 \ n = % a \ n " pr ( I . logor I . one p2 ) ; Printf . printf " 1 | 2 ^ 300 \ n = % a \ n " pr ( I . logor I . one p300 ) ; Printf . printf " 2 ^ 120 | 2 ^ 300 \ n = % a \ n " pr ( I . logor p120 p300 ) ; Printf . printf " 2 ^ 300 | 2 ^ 120 \ n = % a \ n " pr ( I . logor p300 p120 ) ; Printf . printf " 2 ^ 300 | 2 ^ 300 \ n = % a \ n " pr ( I . logor p300 p300 ) ; Printf . printf " 2 ^ 300 | 0 \ n = % a \ n " pr ( I . logor p300 I . zero ) ; Printf . printf " - 2 ^ 120 | 2 ^ 300 \ n = % a \ n " pr ( I . logor ( I . neg p120 ) p300 ) ; Printf . printf " 2 ^ 120 | - 2 ^ 300 \ n = % a \ n " pr ( I . logor p120 ( I . neg p300 ) ) ; Printf . printf " - 2 ^ 120 | - 2 ^ 300 \ n = % a \ n " pr ( I . logor ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " - 2 ^ 300 | 2 ^ 120 \ n = % a \ n " pr ( I . logor ( I . neg p300 ) p120 ) ; Printf . printf " 2 ^ 300 | - 2 ^ 120 \ n = % a \ n " pr ( I . logor p300 ( I . neg p120 ) ) ; Printf . printf " - 2 ^ 300 | - 2 ^ 120 \ n = % a \ n " pr ( I . logor ( I . neg p300 ) ( I . neg p120 ) ) ; Printf . printf " 1 ^ 2 \ n = % a \ n " pr ( I . logxor I . one p2 ) ; Printf . printf " 1 ^ 2 ^ 300 \ n = % a \ n " pr ( I . logxor I . one p300 ) ; Printf . printf " 2 ^ 120 ^ 2 ^ 300 \ n = % a \ n " pr ( I . logxor p120 p300 ) ; Printf . printf " 2 ^ 300 ^ 2 ^ 120 \ n = % a \ n " pr ( I . logxor p300 p120 ) ; Printf . printf " 2 ^ 300 ^ 2 ^ 300 \ n = % a \ n " pr ( I . logxor p300 p300 ) ; Printf . printf " 2 ^ 300 ^ 0 \ n = % a \ n " pr ( I . logxor p300 I . zero ) ; Printf . printf " - 2 ^ 120 ^ 2 ^ 300 \ n = % a \ n " pr ( I . logxor ( I . neg p120 ) p300 ) ; Printf . printf " 2 ^ 120 ^ - 2 ^ 300 \ n = % a \ n " pr ( I . logxor p120 ( I . neg p300 ) ) ; Printf . printf " - 2 ^ 120 ^ - 2 ^ 300 \ n = % a \ n " pr ( I . logxor ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " - 2 ^ 300 ^ 2 ^ 120 \ n = % a \ n " pr ( I . logxor ( I . neg p300 ) p120 ) ; Printf . printf " 2 ^ 300 ^ - 2 ^ 120 \ n = % a \ n " pr ( I . logxor p300 ( I . neg p120 ) ) ; Printf . printf " - 2 ^ 300 ^ - 2 ^ 120 \ n = % a \ n " pr ( I . logxor ( I . neg p300 ) ( I . neg p120 ) ) ; Printf . printf " ~ 0 \ n = % a \ n " pr ( I . lognot I . zero ) ; Printf . printf " ~ 1 \ n = % a \ n " pr ( I . lognot I . one ) ; Printf . printf " ~ 2 \ n = % a \ n " pr ( I . lognot p2 ) ; Printf . printf " ~ 2 ^ 300 \ n = % a \ n " pr ( I . lognot p300 ) ; Printf . printf " ( ~- 1 ) \ n = % a \ n " pr ( I . lognot I . minus_one ) ; Printf . printf " ( ~- 2 ) \ n = % a \ n " pr ( I . lognot ( I . neg p2 ) ) ; Printf . printf " ( ( ~- 2 ^ 300 ) ) \ n = % a \ n " pr ( I . lognot ( I . neg p300 ) ) ; Printf . printf " 0 >> 1 \ n = % a \ n " pr ( I . shift_right I . zero 1 ) ; Printf . printf " 0 >> 100 \ n = % a \ n " pr ( I . shift_right I . zero 100 ) ; Printf . printf " 2 >> 1 \ n = % a \ n " pr ( I . shift_right p2 1 ) ; Printf . printf " 2 >> 2 \ n = % a \ n " pr ( I . shift_right p2 2 ) ; Printf . printf " 2 >> 100 \ n = % a \ n " pr ( I . shift_right p2 100 ) ; Printf . printf " 2 ^ 300 >> 1 \ n = % a \ n " pr ( I . shift_right p300 1 ) ; Printf . printf " 2 ^ 300 >> 2 \ n = % a \ n " pr ( I . shift_right p300 2 ) ; Printf . printf " 2 ^ 300 >> 100 \ n = % a \ n " pr ( I . shift_right p300 100 ) ; Printf . printf " 2 ^ 300 >> 200 \ n = % a \ n " pr ( I . shift_right p300 200 ) ; Printf . printf " 2 ^ 300 >> 300 \ n = % a \ n " pr ( I . shift_right p300 300 ) ; Printf . printf " 2 ^ 300 >> 400 \ n = % a \ n " pr ( I . shift_right p300 400 ) ; Printf . printf " - 1 >> 1 \ n = % a \ n " pr ( I . shift_right I . minus_one 1 ) ; Printf . printf " - 2 >> 1 \ n = % a \ n " pr ( I . shift_right ( I . neg p2 ) 1 ) ; Printf . printf " - 2 >> 2 \ n = % a \ n " pr ( I . shift_right ( I . neg p2 ) 2 ) ; Printf . printf " - 2 >> 100 \ n = % a \ n " pr ( I . shift_right ( I . neg p2 ) 100 ) ; Printf . printf " - 2 ^ 300 >> 1 \ n = % a \ n " pr ( I . shift_right ( I . neg p300 ) 1 ) ; Printf . printf " - 2 ^ 300 >> 2 \ n = % a \ n " pr ( I . shift_right ( I . neg p300 ) 2 ) ; Printf . printf " - 2 ^ 300 >> 100 \ n = % a \ n " pr ( I . shift_right ( I . neg p300 ) 100 ) ; Printf . printf " - 2 ^ 300 >> 200 \ n = % a \ n " pr ( I . shift_right ( I . neg p300 ) 200 ) ; Printf . printf " - 2 ^ 300 >> 300 \ n = % a \ n " pr ( I . shift_right ( I . neg p300 ) 300 ) ; Printf . printf " - 2 ^ 300 >> 400 \ n = % a \ n " pr ( I . shift_right ( I . neg p300 ) 400 ) ; Printf . printf " 0 >> 0 1 \ n = % a \ n " pr ( I . shift_right_trunc I . zero 1 ) ; Printf . printf " 0 >> 0 100 \ n = % a \ n " pr ( I . shift_right_trunc I . zero 100 ) ; Printf . printf " 2 >> 0 1 \ n = % a \ n " pr ( I . shift_right_trunc p2 1 ) ; Printf . printf " 2 >> 0 2 \ n = % a \ n " pr ( I . shift_right_trunc p2 2 ) ; Printf . printf " 2 >> 0 100 \ n = % a \ n " pr ( I . shift_right_trunc p2 100 ) ; Printf . printf " 2 ^ 300 >> 0 1 \ n = % a \ n " pr ( I . shift_right_trunc p300 1 ) ; Printf . printf " 2 ^ 300 >> 0 2 \ n = % a \ n " pr ( I . shift_right_trunc p300 2 ) ; Printf . printf " 2 ^ 300 >> 0 100 \ n = % a \ n " pr ( I . shift_right_trunc p300 100 ) ; Printf . printf " 2 ^ 300 >> 0 200 \ n = % a \ n " pr ( I . shift_right_trunc p300 200 ) ; Printf . printf " 2 ^ 300 >> 0 300 \ n = % a \ n " pr ( I . shift_right_trunc p300 300 ) ; Printf . printf " 2 ^ 300 >> 0 400 \ n = % a \ n " pr ( I . shift_right_trunc p300 400 ) ; Printf . printf " - 1 >> 0 1 \ n = % a \ n " pr ( I . shift_right_trunc I . minus_one 1 ) ; Printf . printf " - 2 >> 0 1 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p2 ) 1 ) ; Printf . printf " - 2 >> 0 2 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p2 ) 2 ) ; Printf . printf " - 2 >> 0 100 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p2 ) 100 ) ; Printf . printf " - 2 ^ 300 >> 0 1 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p300 ) 1 ) ; Printf . printf " - 2 ^ 300 >> 0 2 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p300 ) 2 ) ; Printf . printf " - 2 ^ 300 >> 0 100 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p300 ) 100 ) ; Printf . printf " - 2 ^ 300 >> 0 200 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p300 ) 200 ) ; Printf . printf " - 2 ^ 300 >> 0 300 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p300 ) 300 ) ; Printf . printf " - 2 ^ 300 >> 0 400 \ n = % a \ n " pr ( I . shift_right_trunc ( I . neg p300 ) 400 ) ; Printf . printf " 0 << 1 \ n = % a \ n " pr ( I . shift_left I . zero 1 ) ; Printf . printf " 0 << 100 \ n = % a \ n " pr ( I . shift_left I . zero 100 ) ; Printf . printf " 2 << 1 \ n = % a \ n " pr ( I . shift_left p2 1 ) ; Printf . printf " 2 << 32 \ n = % a \ n " pr ( I . shift_left p2 32 ) ; Printf . printf " 2 << 64 \ n = % a \ n " pr ( I . shift_left p2 64 ) ; Printf . printf " 2 << 299 \ n = % a \ n " pr ( I . shift_left p2 299 ) ; Printf . printf " 2 ^ 120 << 1 \ n = % a \ n " pr ( I . shift_left p120 1 ) ; Printf . printf " 2 ^ 120 << 180 \ n = % a \ n " pr ( I . shift_left p120 180 ) ; Printf . printf " compare 1 2 \ n = % i \ n " ( I . compare I . one p2 ) ; Printf . printf " compare 1 1 \ n = % i \ n " ( I . compare I . one I . one ) ; Printf . printf " compare 2 1 \ n = % i \ n " ( I . compare p2 I . one ) ; Printf . printf " compare 2 ^ 300 2 ^ 120 \ n = % i \ n " ( I . compare p300 p120 ) ; Printf . printf " compare 2 ^ 120 2 ^ 120 \ n = % i \ n " ( I . compare p120 p120 ) ; Printf . printf " compare 2 ^ 120 2 ^ 300 \ n = % i \ n " ( I . compare p120 p300 ) ; Printf . printf " compare 2 ^ 121 2 ^ 120 \ n = % i \ n " ( I . compare p121 p120 ) ; Printf . printf " compare 2 ^ 120 2 ^ 121 \ n = % i \ n " ( I . compare p120 p121 ) ; Printf . printf " compare 2 ^ 300 - 2 ^ 120 \ n = % i \ n " ( I . compare p300 ( I . neg p120 ) ) ; Printf . printf " compare 2 ^ 120 - 2 ^ 120 \ n = % i \ n " ( I . compare p120 ( I . neg p120 ) ) ; Printf . printf " compare 2 ^ 120 - 2 ^ 300 \ n = % i \ n " ( I . compare p120 ( I . neg p300 ) ) ; Printf . printf " compare - 2 ^ 300 2 ^ 120 \ n = % i \ n " ( I . compare ( I . neg p300 ) p120 ) ; Printf . printf " compare - 2 ^ 120 2 ^ 120 \ n = % i \ n " ( I . compare ( I . neg p120 ) p120 ) ; Printf . printf " compare - 2 ^ 120 2 ^ 300 \ n = % i \ n " ( I . compare ( I . neg p120 ) p300 ) ; Printf . printf " compare - 2 ^ 300 - 2 ^ 120 \ n = % i \ n " ( I . compare ( I . neg p300 ) ( I . neg p120 ) ) ; Printf . printf " compare - 2 ^ 120 - 2 ^ 120 \ n = % i \ n " ( I . compare ( I . neg p120 ) ( I . neg p120 ) ) ; Printf . printf " compare - 2 ^ 120 - 2 ^ 300 \ n = % i \ n " ( I . compare ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " equal 1 2 \ n = % B \ n " ( I . equal I . one p2 ) ; Printf . printf " equal 1 1 \ n = % B \ n " ( I . equal I . one I . one ) ; Printf . printf " equal 2 1 \ n = % B \ n " ( I . equal p2 I . one ) ; Printf . printf " equal 2 ^ 300 2 ^ 120 \ n = % B \ n " ( I . equal p300 p120 ) ; Printf . printf " equal 2 ^ 120 2 ^ 120 \ n = % B \ n " ( I . equal p120 p120 ) ; Printf . printf " equal 2 ^ 120 2 ^ 300 \ n = % B \ n " ( I . equal p120 p300 ) ; Printf . printf " equal 2 ^ 121 2 ^ 120 \ n = % B \ n " ( I . equal p121 p120 ) ; Printf . printf " equal 2 ^ 120 2 ^ 121 \ n = % B \ n " ( I . equal p120 p121 ) ; Printf . printf " equal 2 ^ 120 - 2 ^ 120 \ n = % B \ n " ( I . equal p120 ( I . neg p120 ) ) ; Printf . printf " equal - 2 ^ 120 2 ^ 120 \ n = % B \ n " ( I . equal ( I . neg p120 ) p120 ) ; Printf . printf " equal - 2 ^ 120 - 2 ^ 120 \ n = % B \ n " ( I . equal ( I . neg p120 ) ( I . neg p120 ) ) ; Printf . printf " sign 0 \ n = % i \ n " ( I . sign I . zero ) ; Printf . printf " sign 1 \ n = % i \ n " ( I . sign I . one ) ; Printf . printf " sign - 1 \ n = % i \ n " ( I . sign I . minus_one ) ; Printf . printf " sign 2 ^ 300 \ n = % i \ n " ( I . sign p300 ) ; Printf . printf " sign - 2 ^ 300 \ n = % i \ n " ( I . sign ( I . neg p300 ) ) ; Printf . printf " gcd 0 0 \ n = % a \ n " pr ( I . gcd I . zero I . zero ) ; Printf . printf " gcd 0 - 137 \ n = % a \ n " pr ( I . gcd ( I . of_int 0 ) ( I . of_int ( - 137 ) ) ) ; Printf . printf " gcd 12 27 \ n = % a \ n " pr ( I . gcd ( I . of_int 12 ) ( I . of_int 27 ) ) ; Printf . printf " gcd 27 12 \ n = % a \ n " pr ( I . gcd ( I . of_int 27 ) ( I . of_int 12 ) ) ; Printf . printf " gcd 27 27 \ n = % a \ n " pr ( I . gcd ( I . of_int 27 ) ( I . of_int 27 ) ) ; Printf . printf " gcd - 12 27 \ n = % a \ n " pr ( I . gcd ( I . of_int ( - 12 ) ) ( I . of_int 27 ) ) ; Printf . printf " gcd 12 - 27 \ n = % a \ n " pr ( I . gcd ( I . of_int 12 ) ( I . of_int ( - 27 ) ) ) ; Printf . printf " gcd - 12 - 27 \ n = % a \ n " pr ( I . gcd ( I . of_int ( - 12 ) ) ( I . of_int ( - 27 ) ) ) ; Printf . printf " gcd 0 2 ^ 300 \ n = % a \ n " pr ( I . gcd ( I . of_int 0 ) p300 ) ; Printf . printf " gcd 2 ^ 120 2 ^ 300 \ n = % a \ n " pr ( I . gcd p120 p300 ) ; Printf . printf " gcd 2 ^ 300 2 ^ 120 \ n = % a \ n " pr ( I . gcd p300 p120 ) ; Printf . printf " gcd 0 - 2 ^ 300 \ n = % a \ n " pr ( I . gcd ( I . of_int 0 ) ( I . neg p300 ) ) ; Printf . printf " gcd 2 ^ 120 - 2 ^ 300 \ n = % a \ n " pr ( I . gcd p120 ( I . neg p300 ) ) ; Printf . printf " gcd 2 ^ 300 - 2 ^ 120 \ n = % a \ n " pr ( I . gcd p300 ( I . neg p120 ) ) ; Printf . printf " gcd - 2 ^ 120 2 ^ 300 \ n = % a \ n " pr ( I . gcd ( I . neg p120 ) p300 ) ; Printf . printf " gcd - 2 ^ 300 2 ^ 120 \ n = % a \ n " pr ( I . gcd ( I . neg p300 ) p120 ) ; Printf . printf " gcd - 2 ^ 120 - 2 ^ 300 \ n = % a \ n " pr ( I . gcd ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " gcd - 2 ^ 300 - 2 ^ 120 \ n = % a \ n " pr ( I . gcd ( I . neg p300 ) ( I . neg p120 ) ) ; Printf . printf " gcdext 12 27 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int 12 ) ( I . of_int 27 ) ) ; Printf . printf " gcdext 27 12 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int 27 ) ( I . of_int 12 ) ) ; Printf . printf " gcdext 27 27 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int 27 ) ( I . of_int 27 ) ) ; Printf . printf " gcdext - 12 27 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int ( - 12 ) ) ( I . of_int 27 ) ) ; Printf . printf " gcdext 12 - 27 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int 12 ) ( I . of_int ( - 27 ) ) ) ; Printf . printf " gcdext - 12 - 27 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int ( - 12 ) ) ( I . of_int ( - 27 ) ) ) ; Printf . printf " gcdext 2 ^ 120 2 ^ 300 \ n = % a \ n " pr3 ( I . gcdext p120 p300 ) ; Printf . printf " gcdext 2 ^ 300 2 ^ 120 \ n = % a \ n " pr3 ( I . gcdext p300 p120 ) ; Printf . printf " gcdext 12 0 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int 12 ) I . zero ) ; Printf . printf " gcdext 0 27 \ n = % a \ n " pr3 ( I . gcdext I . zero ( I . of_int 27 ) ) ; Printf . printf " gcdext - 12 0 \ n = % a \ n " pr3 ( I . gcdext ( I . of_int ( - 12 ) ) I . zero ) ; Printf . printf " gcdext 0 - 27 \ n = % a \ n " pr3 ( I . gcdext I . zero ( I . of_int ( - 27 ) ) ) ; Printf . printf " gcdext 2 ^ 120 0 \ n = % a \ n " pr3 ( I . gcdext p120 I . zero ) ; Printf . printf " gcdext 0 2 ^ 300 \ n = % a \ n " pr3 ( I . gcdext I . zero p300 ) ; Printf . printf " gcdext - 2 ^ 120 0 \ n = % a \ n " pr3 ( I . gcdext ( I . neg p120 ) I . zero ) ; Printf . printf " gcdext 0 - 2 ^ 300 \ n = % a \ n " pr3 ( I . gcdext I . zero ( I . neg p300 ) ) ; Printf . printf " gcdext 0 0 \ n = % a \ n " pr3 ( I . gcdext I . zero I . zero ) ; Printf . printf " lcm 0 0 = % a \ n " pr ( I . lcm I . zero I . zero ) ; Printf . printf " lcm 10 12 = % a \ n " pr ( I . lcm ( I . of_int 10 ) ( I . of_int 12 ) ) ; Printf . printf " lcm - 10 12 = % a \ n " pr ( I . lcm ( I . of_int ( - 10 ) ) ( I . of_int 12 ) ) ; Printf . printf " lcm 10 - 12 = % a \ n " pr ( I . lcm ( I . of_int 10 ) ( I . of_int ( - 12 ) ) ) ; Printf . printf " lcm - 10 - 12 = % a \ n " pr ( I . lcm ( I . of_int ( - 10 ) ) ( I . of_int ( - 12 ) ) ) ; Printf . printf " lcm 0 12 = % a \ n " pr ( I . lcm I . zero ( I . of_int 12 ) ) ; Printf . printf " lcm 0 - 12 = % a \ n " pr ( I . lcm I . zero ( I . of_int ( - 12 ) ) ) ; Printf . printf " lcm 10 0 = % a \ n " pr ( I . lcm ( I . of_int 10 ) I . zero ) ; Printf . printf " lcm - 10 0 = % a \ n " pr ( I . lcm ( I . of_int ( - 10 ) ) I . zero ) ; Printf . printf " lcm 2 ^ 120 2 ^ 300 = % a \ n " pr ( I . lcm p120 p300 ) ; Printf . printf " lcm 2 ^ 120 - 2 ^ 300 = % a \ n " pr ( I . lcm p120 ( I . neg p300 ) ) ; Printf . printf " lcm - 2 ^ 120 2 ^ 300 = % a \ n " pr ( I . lcm ( I . neg p120 ) p300 ) ; Printf . printf " lcm - 2 ^ 120 - 2 ^ 300 = % a \ n " pr ( I . lcm ( I . neg p120 ) ( I . neg p300 ) ) ; Printf . printf " lcm 2 ^ 120 0 = % a \ n " pr ( I . lcm p120 I . zero ) ; Printf . printf " lcm - 2 ^ 120 0 = % a \ n " pr ( I . lcm ( I . neg p120 ) I . zero ) ; Printf . printf " is_odd 0 \ n = % b \ n " ( I . is_odd ( Z . of_int 0 ) ) ; Printf . printf " is_odd 1 \ n = % b \ n " ( I . is_odd ( Z . of_int 1 ) ) ; Printf . printf " is_odd 2 \ n = % b \ n " ( I . is_odd ( Z . of_int 2 ) ) ; Printf . printf " is_odd 3 \ n = % b \ n " ( I . is_odd ( Z . of_int 3 ) ) ; Printf . printf " is_odd 2 ^ 120 \ n = % b \ n " ( I . is_odd p120 ) ; Printf . printf " is_odd 2 ^ 120 + 1 \ n = % b \ n " ( I . is_odd ( Z . succ p120 ) ) ; Printf . printf " is_odd 2 ^ 300 \ n = % b \ n " ( I . is_odd p300 ) ; Printf . printf " is_odd 2 ^ 300 + 1 \ n = % b \ n " ( I . is_odd ( Z . succ p300 ) ) ; Printf . printf " sqrt 0 \ n = % a \ n " pr ( I . sqrt I . zero ) ; Printf . printf " sqrt 1 \ n = % a \ n " pr ( I . sqrt I . one ) ; Printf . printf " sqrt 2 \ n = % a \ n " pr ( I . sqrt p2 ) ; Printf . printf " sqrt 2 ^ 120 \ n = % a \ n " pr ( I . sqrt p120 ) ; Printf . printf " sqrt 2 ^ 121 \ n = % a \ n " pr ( I . sqrt p121 ) ; Printf . printf " sqrt_rem 0 \ n = % a \ n " pr2 ( I . sqrt_rem I . zero ) ; Printf . printf " sqrt_rem 1 \ n = % a \ n " pr2 ( I . sqrt_rem I . one ) ; Printf . printf " sqrt_rem 2 \ n = % a \ n " pr2 ( I . sqrt_rem p2 ) ; Printf . printf " sqrt_rem 2 ^ 120 \ n = % a \ n " pr2 ( I . sqrt_rem p120 ) ; Printf . printf " sqrt_rem 2 ^ 121 \ n = % a \ n " pr2 ( I . sqrt_rem p121 ) ; Printf . printf " popcount 0 \ n = % i \ n " ( I . popcount I . zero ) ; Printf . printf " popcount 1 \ n = % i \ n " ( I . popcount I . one ) ; Printf . printf " popcount 2 \ n = % i \ n " ( I . popcount p2 ) ; Printf . printf " popcount max_int32 \ n = % i \ n " ( I . popcount maxi32 ) ; Printf . printf " popcount 2 ^ 120 \ n = % i \ n " ( I . popcount p120 ) ; Printf . printf " popcount ( 2 ^ 120 - 1 ) \ n = % i \ n " ( I . popcount ( I . pred p120 ) ) ; Printf . printf " hamdist 0 0 \ n = % i \ n " ( I . hamdist I . zero I . zero ) ; Printf . printf " hamdist 0 1 \ n = % i \ n " ( I . hamdist I . zero I . one ) ; Printf . printf " hamdist 0 2 ^ 300 \ n = % i \ n " ( I . hamdist I . zero p300 ) ; Printf . printf " hamdist 2 ^ 120 2 ^ 120 \ n = % i \ n " ( I . hamdist p120 p120 ) ; Printf . printf " hamdist 2 ^ 120 ( 2 ^ 120 - 1 ) \ n = % i \ n " ( I . hamdist p120 ( I . pred p120 ) ) ; Printf . printf " hamdist 2 ^ 120 2 ^ 300 \ n = % i \ n " ( I . hamdist p120 p300 ) ; Printf . printf " hamdist ( 2 ^ 120 - 1 ) ( 2 ^ 300 - 1 ) \ n = % i \ n " ( I . hamdist ( I . pred p120 ) ( I . pred p300 ) ) ; Printf . printf " hash ( 2 ^ 120 ) \ n = % i \ n " ( Hashtbl . hash p120 ) ; Printf . printf " hash ( 2 ^ 121 ) \ n = % i \ n " ( Hashtbl . hash p121 ) ; Printf . printf " hash ( 2 ^ 300 ) \ n = % i \ n " ( Hashtbl . hash p300 ) ; Printf . printf " 2 ^ 120 = 2 ^ 300 \ n = % B \ n " ( p120 = p300 ) ; Printf . printf " 2 ^ 120 = 2 ^ 120 \ n = % B \ n " ( p120 = p120 ) ; Printf . printf " 2 ^ 120 = 2 ^ 120 \ n = % B \ n " ( p120 = ( pow2 120 ) ) ; Printf . printf " 2 ^ 120 > 2 ^ 300 \ n = % B \ n " ( p120 > p300 ) ; Printf . printf " 2 ^ 120 < 2 ^ 300 \ n = % B \ n " ( p120 < p300 ) ; Printf . printf " 2 ^ 120 = 1 \ n = % B \ n " ( p120 = I . one ) ; Printf . printf " 2 ^ 120 > 1 \ n = % B \ n " ( p120 > I . one ) ; Printf . printf " 2 ^ 120 < 1 \ n = % B \ n " ( p120 < I . one ) ; Printf . printf " - 2 ^ 120 > 1 \ n = % B \ n " ( ( I . neg p120 ) > I . one ) ; Printf . printf " - 2 ^ 120 < 1 \ n = % B \ n " ( ( I . neg p120 ) < I . one ) ; Printf . printf " demarshal 2 ^ 120 , 2 ^ 300 , 1 \ n = % a \ n " pr3 ( Marshal . from_string ( Marshal . to_string ( p120 , p300 , I . one ) [ ] ) 0 ) ; Printf . printf " demarshal - 2 ^ 120 , - 2 ^ 300 , - 1 \ n = % a \ n " pr3 ( Marshal . from_string ( Marshal . to_string ( I . neg p120 , I . neg p300 , I . minus_one ) [ ] ) 0 ) ; Printf . printf " format %% i 0 = /% s /\ n " ( I . format " % i " I . zero ) ; Printf . printf " format %% i 1 = /% s /\ n " ( I . format " % i " I . one ) ; Printf . printf " format %% i - 1 = /% s /\ n " ( I . format " % i " I . minus_one ) ; Printf . printf " format %% i 2 ^ 30 = /% s /\ n " ( I . format " % i " p30 ) ; Printf . printf " format %% i - 2 ^ 30 = /% s /\ n " ( I . format " % i " ( I . neg p30 ) ) ; Printf . printf " format %% i 1 = /% s /\ n " ( I . format " % i " I . one ) ; Printf . printf " format %%+ i 1 = /% s /\ n " ( I . format " %+ i " I . one ) ; Printf . printf " format %% x 0 = /% s /\ n " ( I . format " % x " I . zero ) ; Printf . printf " format %% x 1 = /% s /\ n " ( I . format " % x " I . one ) ; Printf . printf " format %% x - 1 = /% s /\ n " ( I . format " % x " I . minus_one ) ; Printf . printf " format %% x 2 ^ 30 = /% s /\ n " ( I . format " % x " p30 ) ; Printf . printf " format %% x - 2 ^ 30 = /% s /\ n " ( I . format " % x " ( I . neg p30 ) ) ; Printf . printf " format %% X 0 = /% s /\ n " ( I . format " % X " I . zero ) ; Printf . printf " format %% X 1 = /% s /\ n " ( I . format " % X " I . one ) ; Printf . printf " format %% X - 1 = /% s /\ n " ( I . format " % X " I . minus_one ) ; Printf . printf " format %% X 2 ^ 30 = /% s /\ n " ( I . format " % X " p30 ) ; Printf . printf " format %% X - 2 ^ 30 = /% s /\ n " ( I . format " % X " ( I . neg p30 ) ) ; Printf . printf " format %% o 0 = /% s /\ n " ( I . format " % o " I . zero ) ; Printf . printf " format %% o 1 = /% s /\ n " ( I . format " % o " I . one ) ; Printf . printf " format %% o - 1 = /% s /\ n " ( I . format " % o " I . minus_one ) ; Printf . printf " format %% o 2 ^ 30 = /% s /\ n " ( I . format " % o " p30 ) ; Printf . printf " format %% o - 2 ^ 30 = /% s /\ n " ( I . format " % o " ( I . neg p30 ) ) ; Printf . printf " format %% 10i 0 = /% s /\ n " ( I . format " % 10i " I . zero ) ; Printf . printf " format %% 10i 1 = /% s /\ n " ( I . format " % 10i " I . one ) ; Printf . printf " format %% 10i - 1 = /% s /\ n " ( I . format " % 10i " I . minus_one ) ; Printf . printf " format %% 10i 2 ^ 30 = /% s /\ n " ( I . format " % 10i " p30 ) ; Printf . printf " format %% 10i - 2 ^ 30 = /% s /\ n " ( I . format " % 10i " ( I . neg p30 ) ) ; Printf . printf " format %%- 10i 0 = /% s /\ n " ( I . format " %- 10i " I . zero ) ; Printf . printf " format %%- 10i 1 = /% s /\ n " ( I . format " %- 10i " I . one ) ; Printf . printf " format %%- 10i - 1 = /% s /\ n " ( I . format " %- 10i " I . minus_one ) ; Printf . printf " format %%- 10i 2 ^ 30 = /% s /\ n " ( I . format " %- 10i " p30 ) ; Printf . printf " format %%- 10i - 2 ^ 30 = /% s /\ n " ( I . format " %- 10i " ( I . neg p30 ) ) ; Printf . printf " format %%+ 10i 0 = /% s /\ n " ( I . format " %+ 10i " I . zero ) ; Printf . printf " format %%+ 10i 1 = /% s /\ n " ( I . format " %+ 10i " I . one ) ; Printf . printf " format %%+ 10i - 1 = /% s /\ n " ( I . format " %+ 10i " I . minus_one ) ; Printf . printf " format %%+ 10i 2 ^ 30 = /% s /\ n " ( I . format " %+ 10i " p30 ) ; Printf . printf " format %%+ 10i - 2 ^ 30 = /% s /\ n " ( I . format " %+ 10i " ( I . neg p30 ) ) ; Printf . printf " format %% 10i 0 = /% s /\ n " ( I . format " % 10i " I . zero ) ; Printf . printf " format %% 10i 1 = /% s /\ n " ( I . format " % 10i " I . one ) ; Printf . printf " format %% 10i - 1 = /% s /\ n " ( I . format " % 10i " I . minus_one ) ; Printf . printf " format %% 10i 2 ^ 30 = /% s /\ n " ( I . format " % 10i " p30 ) ; Printf . printf " format %% 10i - 2 ^ 30 = /% s /\ n " ( I . format " % 10i " ( I . neg p30 ) ) ; Printf . printf " format %% 010i 0 = /% s /\ n " ( I . format " % 010i " I . zero ) ; Printf . printf " format %% 010i 1 = /% s /\ n " ( I . format " % 010i " I . one ) ; Printf . printf " format %% 010i - 1 = /% s /\ n " ( I . format " % 010i " I . minus_one ) ; Printf . printf " format %% 010i 2 ^ 30 = /% s /\ n " ( I . format " % 010i " p30 ) ; Printf . printf " format %% 010i - 2 ^ 30 = /% s /\ n " ( I . format " % 010i " ( I . neg p30 ) ) ; Printf . printf " format %%# x 0 = /% s /\ n " ( I . format " %# x " I . zero ) ; Printf . printf " format %%# x 1 = /% s /\ n " ( I . format " %# x " I . one ) ; Printf . printf " format %%# x - 1 = /% s /\ n " ( I . format " %# x " I . minus_one ) ; Printf . printf " format %%# x 2 ^ 30 = /% s /\ n " ( I . format " %# x " p30 ) ; Printf . printf " format %%# x - 2 ^ 30 = /% s /\ n " ( I . format " %# x " ( I . neg p30 ) ) ; Printf . printf " format %%# X 0 = /% s /\ n " ( I . format " %# X " I . zero ) ; Printf . printf " format %%# X 1 = /% s /\ n " ( I . format " %# X " I . one ) ; Printf . printf " format %%# X - 1 = /% s /\ n " ( I . format " %# X " I . minus_one ) ; Printf . printf " format %%# X 2 ^ 30 = /% s /\ n " ( I . format " %# X " p30 ) ; Printf . printf " format %%# X - 2 ^ 30 = /% s /\ n " ( I . format " %# X " ( I . neg p30 ) ) ; Printf . printf " format %%# o 0 = /% s /\ n " ( I . format " %# o " I . zero ) ; Printf . printf " format %%# o 1 = /% s /\ n " ( I . format " %# o " I . one ) ; Printf . printf " format %%# o - 1 = /% s /\ n " ( I . format " %# o " I . minus_one ) ; Printf . printf " format %%# o 2 ^ 30 = /% s /\ n " ( I . format " %# o " p30 ) ; Printf . printf " format %%# o - 2 ^ 30 = /% s /\ n " ( I . format " %# o " ( I . neg p30 ) ) ; Printf . printf " format %%# 10x 0 = /% s /\ n " ( I . format " %# 10x " I . zero ) ; Printf . printf " format %%# 10x 1 = /% s /\ n " ( I . format " %# 10x " I . one ) ; Printf . printf " format %%# 10x - 1 = /% s /\ n " ( I . format " %# 10x " I . minus_one ) ; Printf . printf " format %%# 10x 2 ^ 30 = /% s /\ n " ( I . format " %# 10x " p30 ) ; Printf . printf " format %%# 10x - 2 ^ 30 = /% s /\ n " ( I . format " %# 10x " ( I . neg p30 ) ) ; Printf . printf " format %%# 10X 0 = /% s /\ n " ( I . format " %# 10X " I . zero ) ; Printf . printf " format %%# 10X 1 = /% s /\ n " ( I . format " %# 10X " I . one ) ; Printf . printf " format %%# 10X - 1 = /% s /\ n " ( I . format " %# 10X " I . minus_one ) ; Printf . printf " format %%# 10X 2 ^ 30 = /% s /\ n " ( I . format " %# 10X " p30 ) ; Printf . printf " format %%# 10X - 2 ^ 30 = /% s /\ n " ( I . format " %# 10X " ( I . neg p30 ) ) ; Printf . printf " format %%# 10o 0 = /% s /\ n " ( I . format " %# 10o " I . zero ) ; Printf . printf " format %%# 10o 1 = /% s /\ n " ( I . format " %# 10o " I . one ) ; Printf . printf " format %%# 10o - 1 = /% s /\ n " ( I . format " %# 10o " I . minus_one ) ; Printf . printf " format %%# 10o 2 ^ 30 = /% s /\ n " ( I . format " %# 10o " p30 ) ; Printf . printf " format %%# 10o - 2 ^ 30 = /% s /\ n " ( I . format " %# 10o " ( I . neg p30 ) ) ; Printf . printf " format %%#- 10x 0 = /% s /\ n " ( I . format " %#- 10x " I . zero ) ; Printf . printf " format %%#- 10x 1 = /% s /\ n " ( I . format " %#- 10x " I . one ) ; Printf . printf " format %%#- 10x - 1 = /% s /\ n " ( I . format " %#- 10x " I . minus_one ) ; Printf . printf " format %%#- 10x 2 ^ 30 = /% s /\ n " ( I . format " %#- 10x " p30 ) ; Printf . printf " format %%#- 10x - 2 ^ 30 = /% s /\ n " ( I . format " %#- 10x " ( I . neg p30 ) ) ; Printf . printf " format %%#- 10X 0 = /% s /\ n " ( I . format " %#- 10X " I . zero ) ; Printf . printf " format %%#- 10X 1 = /% s /\ n " ( I . format " %#- 10X " I . one ) ; Printf . printf " format %%#- 10X - 1 = /% s /\ n " ( I . format " %#- 10X " I . minus_one ) ; Printf . printf " format %%#- 10X 2 ^ 30 = /% s /\ n " ( I . format " %#- 10X " p30 ) ; Printf . printf " format %%#- 10X - 2 ^ 30 = /% s /\ n " ( I . format " %#- 10X " ( I . neg p30 ) ) ; Printf . printf " format %%#- 10o 0 = /% s /\ n " ( I . format " %#- 10o " I . zero ) ; Printf . printf " format %%#- 10o 1 = /% s /\ n " ( I . format " %#- 10o " I . one ) ; Printf . printf " format %%#- 10o - 1 = /% s /\ n " ( I . format " %#- 10o " I . minus_one ) ; Printf . printf " format %%#- 10o 2 ^ 30 = /% s /\ n " ( I . format " %#- 10o " p30 ) ; Printf . printf " format %%#- 10o - 2 ^ 30 = /% s /\ n " ( I . format " %#- 10o " ( I . neg p30 ) ) ; let extract_testdata = let a = I . of_int 42 and b = I . of_int ( - 42 ) and c = I . of_string " 3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701 " in [ a , 0 , 1 ; a , 0 , 5 ; a , 0 , 32 ; a , 0 , 64 ; a , 1 , 1 ; a , 1 , 5 ; a , 1 , 32 ; a , 1 , 63 ; a , 1 , 64 ; a , 1 , 127 ; a , 1 , 128 ; a , 69 , 12 ; b , 0 , 1 ; b , 0 , 5 ; b , 0 , 32 ; b , 0 , 64 ; b , 1 , 1 ; b , 1 , 5 ; b , 1 , 32 ; b , 1 , 63 ; b , 1 , 64 ; b , 1 , 127 ; b , 1 , 128 ; b , 69 , 12 ; c , 0 , 1 ; c , 0 , 64 ; c , 128 , 1 ; c , 128 , 5 ; c , 131 , 32 ; c , 175 , 63 ; c , 277 , 123 ] in List . iter chk_extract extract_testdata ; List . iter chk_signed_extract extract_testdata ; chk_bits I . zero ; chk_bits p2 ; chk_bits ( I . neg p2 ) ; chk_bits p30 ; chk_bits ( I . neg p30 ) ; chk_bits p62 ; chk_bits ( I . neg p62 ) ; chk_bits p300 ; chk_bits p120 ; chk_bits p121 ; chk_bits maxi ; chk_bits mini ; chk_bits maxi32 ; chk_bits mini32 ; chk_bits maxi64 ; chk_bits mini64 ; chk_bits maxni ; chk_bits minni ; List . iter chk_testbit [ I . zero ; I . one ; I . of_int ( - 42 ) ; I . of_string " 31415926535897932384626433832795028841971693993751058209749445923078164062862089986 " ; I . neg ( I . shift_left ( I . of_int 123456 ) 64 ) ; ] ; List . iter chk_numbits_tz [ I . zero ; I . one ; I . of_int ( - 42 ) ; I . shift_left ( I . of_int 9999 ) 77 ; I . neg ( I . shift_left ( I . of_int 123456 ) 64 ) ; ] ; ( )
let gcd2 a b = if Z . sign a = 0 then b else if Z . sign b = 0 then a else Z . gcd a b