package apronext

  1. Overview
  2. Docs

Source file scalarext.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
open Apron
include Scalar

let to_mpqf = function
  | Mpqf x -> x
  | Float x -> Mpqf.of_float x
  | Mpfrf x -> Mpfrf.to_mpqf x

let to_float = function
  | Mpqf x -> Mpqf.to_float x
  | Float x -> x
  | Mpfrf x -> Mpfrf.to_float ~round:Mpfr.Near x

(** scalar addition. result is automatically lifted to mpqf to avoid loss of
    precision *)
let add s1 s2 =
  let x1 = to_mpqf s1 and x2 = to_mpqf s2 in
  Mpqf (Mpqf.add x1 x2)

(** scalar substraction. result is automatically lifted to mpqf to avoid loss of
    precision *)
let sub s1 s2 =
  let x1 = to_mpqf s1 and x2 = to_mpqf s2 in
  Mpqf (Mpqf.sub x1 x2)

(** scalar multiplication. result is automatically lifted to mpqf to avoid loss
    of precision *)
let mul s1 s2 =
  let x1 = to_mpqf s1 and x2 = to_mpqf s2 in
  Mpqf (Mpqf.mul x1 x2)

(** scalar division. result is automatically lifted to mpqf to avoid loss of
    precision *)
let div s1 s2 =
  let x1 = to_mpqf s1 and x2 = to_mpqf s2 in
  Mpqf (Mpqf.div x1 x2)