forked from dune-universe/Zarith
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z_mlgmpidl.ml
49 lines (36 loc) · 1.26 KB
/
z_mlgmpidl.ml
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
(**
Conversion between Zarith and MLGmpIDL integers and rationals.
This file is part of the Zarith library
http://forge.ocamlcore.org/projects/zarith .
It is distributed under LGPL 2 licensing, with static linking exception.
See the LICENSE file included in the distribution.
Copyright (c) 2010-2011 Antoine Miné, Abstraction project.
Abstraction is part of the LIENS (Laboratoire d'Informatique de l'ENS),
a joint laboratory by:
CNRS (Centre national de la recherche scientifique, France),
ENS (École normale supérieure, Paris, France),
INRIA Rocquencourt (Institut national de recherche en informatique, France).
*)
external mlgmpidl_of_mpz: Mpz.t -> Z.t = "ml_z_mlgmpidl_of_mpz"
external mlgmpidl_set_mpz: Mpz.t -> Z.t -> unit = "ml_z_mlgmpidl_set_mpz"
let z_of_mpz x =
mlgmpidl_of_mpz x
let mpz_of_z x =
let r = Mpz.init () in
mlgmpidl_set_mpz r x;
r
let z_of_mpzf x =
z_of_mpz (Mpzf._mpz x)
let mpzf_of_z x =
Mpzf._mpzf (mpz_of_z x)
let q_of_mpq x =
let n,d = Mpz.init (), Mpz.init () in
Mpq.get_num n x;
Mpq.get_den d x;
Q.make (z_of_mpz n) (z_of_mpz d)
let mpq_of_q x =
Mpq.of_mpz2 (mpz_of_z x.Q.num) (mpz_of_z x.Q.den)
let q_of_mpqf x =
q_of_mpq (Mpqf._mpq x)
let mpqf_of_q x =
Mpqf._mpqf (mpq_of_q x)