Changeset 89


Ignore:
Timestamp:
Sep 20, 2010, 11:48:03 AM (9 years ago)
Author:
mulligan
Message:

Fixed a really annoying bug in vect_to_int and int_to_vect

Location:
Deliverables/D4.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/BitVectors.ml

    r88 r89  
    9595  in
    9696    aux 1 (List.rev v)
     97
     98let size_lookup =
     99  function
     100    `Four -> 4
     101  | `Seven -> 7
     102  | `Eight -> 8
     103  | `Eleven -> 11
     104  | `Sixteen -> 16
     105
     106let rec pow v p =
     107  if p = 0 then
     108    1
     109  else
     110    v * (pow v (p - 1))
     111
     112let divide_with_remainder x y = (x / y, x mod y)
     113
     114let rec aux i =
     115  if i < 0 then
     116    raise (Invalid_argument "Negative index")
     117  else
     118    let (d, r) = divide_with_remainder i 2 in
     119      if (d, r) = (0, 0) then
     120        []
     121      else if r = 0 then
     122        false :: aux d
     123      else
     124        true :: aux d
     125
     126let rec pad i l =
     127  match i with
     128    0 -> l
     129  | n -> false :: (pad (i - 1) l)
     130
     131let vect_of_int i size =
     132  let big_list = List.rev (aux i) in
     133    if List.length big_list > (size_lookup size) then
     134      raise (Invalid_argument "Size not big enough")
     135    else
     136      let diff = (size_lookup size) - (List.length big_list) in
     137        pad diff big_list
     138   
  • Deliverables/D4.1/BitVectors.mli

    r88 r89  
    2525
    2626val int_of_vect: 'a vect -> int
    27 val vect_of_int: int -> 'a -> 'a vect
     27val vect_of_int: int -> [`Four | `Seven | `Eight | `Eleven | `Sixteen ] -> [`Four | `Seven | `Eight | `Eleven | `Sixteen ] vect
    2828
    2929val (-&-): 'a vect -> 'a vect -> 'a vect
Note: See TracChangeset for help on using the changeset viewer.