Advertisement
Guest User

Untitled

a guest
Jan 28th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.46 KB | None | 0 0
  1. open Batteries;;
  2.  
  3. let of_float_string a =
  4.   match Str.split (Str.regexp "\\.") a with
  5.       [] -> failwith "Empty string"
  6.     | iprt_str :: [fprt_str] -> (
  7.       let iprt = Num.of_string iprt_str in
  8.       let power = string_of_int (int_of_float (10.0 **
  9.         (float_of_int (String.length fprt_str)))) in
  10.       let fprt = Num.of_string (String.concat "/" [fprt_str; power]) in
  11.       Num.(+) iprt fprt)
  12.     | _ :: a -> failwith "Too much point in the value"
  13.   ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement