File: pretty_gmp.ml

package info (click to toggle)
mlgmp 20021123-20
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 512 kB
  • sloc: ansic: 3,257; ml: 3,126; makefile: 167
file content (62 lines) | stat: -rw-r--r-- 2,239 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(*
 * ML GMP - Interface between Objective Caml and GNU MP
 * Copyright (C) 2001 David MONNIAUX
 * 
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2 published by the Free Software Foundation,
 * or any more recent version published by the Free Software
 * Foundation, at your choice.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * See the GNU Library General Public License version 2 for more details
 * (enclosed in the file LGPL).
 *
 * As a special exception to the GNU Library General Public License, you
 * may link, statically or dynamically, a "work that uses the Library"
 * with a publicly distributed version of the Library to produce an
 * executable file containing portions of the Library, and distribute
 * that executable file under terms of your choice, without any of the
 * additional requirements listed in clause 6 of the GNU Library General
 * Public License.  By "a publicly distributed version of the Library",
 * we mean either the unmodified Library as distributed by INRIA, or a
 * modified version of the Library that is distributed under the
 * conditions defined in clause 3 of the GNU Library General Public
 * License.  This exception does not however invalidate any other reasons
 * why the executable file might be covered by the GNU Library General
 * Public License.
 *)

open Gmp;;
open Format;;

let base = ref 10;;
let precision = ref 10;;

let z formatter x =
  pp_print_string formatter (Z.to_string_base ~base: !base x);;
 
let q formatter x =
  pp_open_hvbox formatter 8;
  z formatter (Q.get_num x);
  pp_close_box formatter ();
  pp_open_hbox formatter ();
  pp_print_string formatter " / ";
  pp_open_hvbox formatter 8;
  z formatter (Q.get_den x);
  pp_close_box formatter ();;

let f formatter x =
  pp_print_string formatter
    (F.to_string_base_digits ~base: !base ~digits: !precision x);;

let fr formatter x =
  pp_print_string formatter
    (FR.to_string_base_digits ~mode: GMP_RNDN
       ~base: !base ~digits: !precision x);;