-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue.h
92 lines (67 loc) · 2.05 KB
/
value.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# Copyright (c) 2016 The Caroline authors. All rights reserved.
# Use of this source file is governed by a MIT license that can be found in the
# LICENSE file.
# Author: Glazachev Vladimir <[email protected]>
#ifndef VALUE_H
#define VALUE_H
#include "precision.h"
#include "flint/arf.h"
/*
This file contains C++ wrapper of Arb library arf_t type for arbitary
precision real values representation.
Now implemented only comparision operations and addition.
*/
namespace interval {
// TODO :
// 1) implement more arf functions;
// Struct to work with real values. It is used for interval value.
// It is also used then you need to work with errors (in internal interval
// implementation used mag_t type).
struct Value {
Value() {
arf_init(data_);
}
~Value() {
arf_clear(data_);
}
arf_t data_;
// double cast.
operator double() const {
return arf_get_d(data_, ARF_RND_UP);
}
// Addition.
Value operator+(const Value& other) {
Value temp;
arf_add(temp.data_, data_, other.data_, getPrecision(), ARF_RND_UP);
return temp;
}
Value operator/(const Value& other) {
Value temp;
arf_div(temp.data_, data_, other.data_, getPrecision(), ARF_RND_UP);
return temp;
}
void print() const {
arf_print(data_);
}
};
// Comparision functions.
inline bool operator==(const Value& x, const Value& y) {
return arf_cmp(x.data_, y.data_) == 0;
}
inline bool operator!=(const Value& x, const Value& y) {
return arf_cmp(x.data_, y.data_) != 0;
}
inline bool operator<(const Value& x, const Value& y) {
return arf_cmp(x.data_, y.data_) < 0;
}
inline bool operator<=(const Value& x, const Value& y) {
return arf_cmp(x.data_, y.data_) <= 0;
}
inline bool operator>(const Value& x, const Value& y) {
return arf_cmp(x.data_, y.data_) > 0;
}
inline bool operator>=(const Value& x, const Value& y) {
return arf_cmp(x.data_, y.data_) >= 0;
}
} // namespace interval
#endif // VALUE_H