1995-11-06 02:34:19 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-11-06 02:34:19 -08:00
|
|
|
(* *)
|
|
|
|
(* Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../../LICENSE. *)
|
1995-11-06 02:34:19 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Some extra operations on integers *)
|
|
|
|
|
2002-05-27 05:06:49 -07:00
|
|
|
let rec gcd_int i1 i2 =
|
|
|
|
if i2 = 0 then abs i1 else gcd_int i2 (i1 mod i2)
|
|
|
|
;;
|
1995-11-06 02:34:19 -08:00
|
|
|
|
2002-05-07 00:41:12 -07:00
|
|
|
let rec num_bits_int_aux n =
|
2002-05-27 05:06:49 -07:00
|
|
|
if n = 0 then 0 else succ(num_bits_int_aux (n lsr 1));;
|
2002-05-07 00:41:12 -07:00
|
|
|
|
|
|
|
let num_bits_int n = num_bits_int_aux (abs n);;
|
|
|
|
|
2002-05-27 05:06:49 -07:00
|
|
|
let sign_int i = if i = 0 then 0 else if i > 0 then 1 else -1;;
|
2002-05-07 00:41:12 -07:00
|
|
|
|
2002-05-27 05:06:49 -07:00
|
|
|
let length_of_int = Sys.word_size - 2;;
|
2002-05-07 00:41:12 -07:00
|
|
|
|
2002-05-27 05:06:49 -07:00
|
|
|
let monster_int = 1 lsl length_of_int;;
|
|
|
|
let biggest_int = monster_int - 1;;
|
|
|
|
let least_int = - biggest_int;;
|
2002-05-07 00:41:12 -07:00
|
|
|
|
2002-05-27 05:06:49 -07:00
|
|
|
let compare_int n1 n2 =
|
|
|
|
if n1 == n2 then 0 else if n1 > n2 then 1 else -1;;
|