42 lines
1.3 KiB
Plaintext
42 lines
1.3 KiB
Plaintext
|
(***********************************************************************)
|
||
|
(* *)
|
||
|
(* Caml Special Light *)
|
||
|
(* *)
|
||
|
(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *)
|
||
|
(* *)
|
||
|
(* Copyright 1995 Institut National de Recherche en Informatique et *)
|
||
|
(* Automatique. Distributed only by permission. *)
|
||
|
(* *)
|
||
|
(***********************************************************************)
|
||
|
|
||
|
(* $Id$ *)
|
||
|
|
||
|
(* Some extra operations on integers *)
|
||
|
|
||
|
(*
|
||
|
#include "../../config/m.h"
|
||
|
*)
|
||
|
|
||
|
let rec gcd_int i1 i2 =
|
||
|
if i2 = 0 then abs i1 else gcd_int i2 (i1 mod i2)
|
||
|
;;
|
||
|
|
||
|
let rec num_bits_int_aux n =
|
||
|
if n = 0 then 0 else succ(num_bits_int_aux (n lsr 1));;
|
||
|
|
||
|
let num_bits_int n = num_bits_int_aux (abs n);;
|
||
|
|
||
|
let sign_int i = if i = 0 then 0 else if i > 0 then 1 else -1;;
|
||
|
|
||
|
#ifdef SIXTYFOUR
|
||
|
let length_of_int = 62;;
|
||
|
#else
|
||
|
let length_of_int = 30;;
|
||
|
#endif
|
||
|
let monster_int = 1 lsl length_of_int;;
|
||
|
let biggest_int = monster_int - 1;;
|
||
|
let least_int = - biggest_int;;
|
||
|
|
||
|
let compare_int n1 n2 =
|
||
|
if n1 == n2 then 0 else if n1 > n2 then 1 else -1;;
|