]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/num/int_misc.ml
Inital import
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / num / int_misc.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                           Objective Caml                            *)
4 (*                                                                     *)
5 (*    Valerie Menissier-Morain, projet Cristal, INRIA Rocquencourt     *)
6 (*                                                                     *)
7 (*  Copyright 1996 Institut National de Recherche en Informatique et   *)
8 (*  en Automatique.  All rights reserved.  This file is distributed    *)
9 (*  under the terms of the GNU Library General Public License, with    *)
10 (*  the special exception on linking described in file ../../LICENSE.  *)
11 (*                                                                     *)
12 (***********************************************************************)
13
14 (* $Id: int_misc.ml 4845 2002-05-27 12:06:49Z weis $ *)
15
16 (* Some extra operations on integers *)
17
18 let rec gcd_int i1 i2 =
19   if i2 = 0 then abs i1 else gcd_int i2 (i1 mod i2)
20 ;;
21
22 let rec num_bits_int_aux n =
23   if n = 0 then 0 else succ(num_bits_int_aux (n lsr 1));;
24
25 let num_bits_int n = num_bits_int_aux (abs n);;
26
27 let sign_int i = if i = 0 then 0 else if i > 0 then 1 else -1;;
28
29 let length_of_int = Sys.word_size - 2;;
30
31 let monster_int = 1 lsl length_of_int;;
32 let biggest_int = monster_int - 1;;
33 let least_int = - biggest_int;;
34
35 let compare_int n1 n2 =
36   if n1 == n2 then 0 else if n1 > n2 then 1 else -1;;