Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
double.cpp
Go to the documentation of this file.
1
12#include <cmath>
13#include <complex>
14
15#include <math.h>
16
19
20namespace libff {
21
22 const double PI = 3.141592653589793238460264338328L;
23
25 {
26 val = std::complex<double>(0, 0);
27 }
28
29 Double::Double(double real)
30 {
31 val = std::complex<double>(real, 0);
32 }
33
34 Double::Double(double real, double imag)
35 {
36 val = std::complex<double>(real, imag);
37 }
38
39 Double::Double(std::complex<double> num)
40 {
41 val = num;
42 }
43
44 unsigned Double::add_cnt = 0;
45 unsigned Double::sub_cnt = 0;
46 unsigned Double::mul_cnt = 0;
47 unsigned Double::inv_cnt = 0;
48
49 Double Double::operator+(const Double &other) const
50 {
51#ifdef PROFILE_OP_COUNTS
52 ++add_cnt;
53#endif
54
55 return Double(val + other.val);
56 }
57
58 Double Double::operator-(const Double &other) const
59 {
60#ifdef PROFILE_OP_COUNTS
61 ++sub_cnt;
62#endif
63
64 return Double(val - other.val);
65 }
66
67 Double Double::operator*(const Double &other) const
68 {
69#ifdef PROFILE_OP_COUNTS
70 ++mul_cnt;
71#endif
72
73 return Double(val * other.val);
74 }
75
77 {
78 if (val.imag() == 0) return Double(-val.real());
79
80 return Double(-val.real(), -val.imag());
81 }
82
84 {
85#ifdef PROFILE_OP_COUNTS
86 ++add_cnt;
87#endif
88
89 this->val = std::complex<double>(val + other.val);
90 return *this;
91 }
92
94 {
95#ifdef PROFILE_OP_COUNTS
96 ++sub_cnt;
97#endif
98
99 this->val = std::complex<double>(val - other.val);
100 return *this;
101 }
102
104 {
105#ifdef PROFILE_OP_COUNTS
106 ++mul_cnt;
107#endif
108
109 this->val *= std::complex<double>(other.val);
110 return *this;
111 }
112
113 bool Double::operator==(const Double &other) const
114 {
115 return (std::abs(val.real() - other.val.real()) < 0.000001)
116 && (std::abs(val.imag() - other.val.imag()) < 0.000001);
117 }
118
119 bool Double::operator!=(const Double &other) const
120 {
121 return Double(val) == other ? 0 : 1;
122 }
123
124 bool Double::operator<(const Double &other) const
125 {
126 return (val.real() < other.val.real());
127 }
128
129 bool Double::operator>(const Double &other) const
130 {
131 return (val.real() > other.val.real());
132 }
133
135 {
136 return Double(pow(val, power.as_ulong()));
137 }
138
139 Double Double::operator^(const size_t power) const
140 {
141 return Double(pow(val, power));
142 }
143
145 {
146#ifdef PROFILE_OP_COUNTS
147 ++inv_cnt;
148#endif
149
150 return Double(std::complex<double>(1) / val);
151 }
152
154 {
155 return libff::bigint<1>(val.real());
156 }
157
158 unsigned long Double::as_ulong() const
159 {
160 return round(val.real());
161 }
162
164 {
165 return Double(val * val);
166 }
167
169 {
170 return Double(1);
171 }
172
174 {
175 return Double(0);
176 }
177
179 {
180 return Double(std::rand() % 1001);
181 }
182
184 {
185 return Double(2);
186 }
187
189 {
190 return Double(1);
191 }
192
194
195} // libff
Double inverse() const
Definition double.cpp:144
static Double geometric_generator()
Definition double.cpp:183
Double & operator*=(const Double &other)
Definition double.cpp:103
static Double random_element()
Definition double.cpp:178
static unsigned add_cnt
Definition double.hpp:34
Double operator^(const libff::bigint< 1 > power) const
Definition double.cpp:134
Double & operator+=(const Double &other)
Definition double.cpp:83
bool operator<(const Double &other) const
Definition double.cpp:124
static Double multiplicative_generator
Definition double.hpp:68
static Double zero()
Definition double.cpp:173
std::complex< double > val
Definition double.hpp:24
static unsigned sub_cnt
Definition double.hpp:35
Double operator+(const Double &other) const
Definition double.cpp:49
static Double arithmetic_generator()
Definition double.cpp:188
libff::bigint< 1 > as_bigint() const
Definition double.cpp:153
bool operator>(const Double &other) const
Definition double.cpp:129
Double squared() const
Definition double.cpp:163
static Double one()
Definition double.cpp:168
Double operator*(const Double &other) const
Definition double.cpp:67
static unsigned inv_cnt
Definition double.hpp:37
bool operator!=(const Double &other) const
Definition double.cpp:119
unsigned long as_ulong() const
Definition double.cpp:158
bool operator==(const Double &other) const
Definition double.cpp:113
Double & operator-=(const Double &other)
Definition double.cpp:93
static unsigned mul_cnt
Definition double.hpp:36
Double operator-() const
Definition double.cpp:76
const double PI
Definition double.cpp:22
FieldT power(const FieldT &base, const bigint< m > &exponent)