Grid 0.7.0
bigfloat_double.h
Go to the documentation of this file.
1 /*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/algorithms/approx/bigfloat_double.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 See the full license in the file "LICENSE" in the top level distribution directory
26 *************************************************************************************/
27 /* END LEGAL */
28
29#ifndef INCLUDED_BIGFLOAT_DOUBLE_H
30#define INCLUDED_BIGFLOAT_DOUBLE_H
31
32#include <math.h>
33
34typedef double mfloat;
35class bigfloat {
36private:
37
39
40public:
41
43 bigfloat(const bigfloat& y) { x=y.x; }
44 bigfloat(const unsigned long u) { x=u; }
45 bigfloat(const long i) { x=i; }
46 bigfloat(const int i) { x=i;}
47 bigfloat(const float d) { x=d;}
48 bigfloat(const double d) { x=d;}
49 bigfloat(const char *str) { x=std::stod(std::string(str));}
50 ~bigfloat(void) { }
51 operator double (void) const { return (double)x; }
52 static void setDefaultPrecision(unsigned long dprec) {
53 }
54
55 void setPrecision(unsigned long dprec) {
56 }
57
58 unsigned long getPrecision(void) const { return 64; }
59 unsigned long getDefaultPrecision(void) const { return 64; }
60
61 bigfloat& operator=(const bigfloat& y) { x=y.x; return *this; }
62 bigfloat& operator=(const unsigned long y) { x=y; return *this; }
63 bigfloat& operator=(const signed long y) { x=y; return *this; }
64 bigfloat& operator=(const float y) { x=y; return *this; }
65 bigfloat& operator=(const double y) { x=y; return *this; }
66
67 size_t write(void);
68 size_t read(void);
69
70 /* Arithmetic Functions */
71
72 bigfloat& operator+=(const bigfloat& y) { return *this = *this + y; }
73 bigfloat& operator-=(const bigfloat& y) { return *this = *this - y; }
74 bigfloat& operator*=(const bigfloat& y) { return *this = *this * y; }
75 bigfloat& operator/=(const bigfloat& y) { return *this = *this / y; }
76
77 friend bigfloat operator+(const bigfloat& x, const bigfloat& y) {
78 bigfloat a;
79 a.x=x.x+y.x;
80 return a;
81 }
82
83 friend bigfloat operator+(const bigfloat& x, const unsigned long y) {
84 bigfloat a;
85 a.x=x.x+y;
86 return a;
87 }
88
89 friend bigfloat operator-(const bigfloat& x, const bigfloat& y) {
90 bigfloat a;
91 a.x=x.x-y.x;
92 return a;
93 }
94
95 friend bigfloat operator-(const unsigned long x, const bigfloat& y) {
96 bigfloat bx(x);
97 return bx-y;
98 }
99
100 friend bigfloat operator-(const bigfloat& x, const unsigned long y) {
101 bigfloat by(y);
102 return x-by;
103 }
104
105 friend bigfloat operator-(const bigfloat& x) {
106 bigfloat a;
107 a.x=-x.x;
108 return a;
109 }
110
111 friend bigfloat operator*(const bigfloat& x, const bigfloat& y) {
112 bigfloat a;
113 a.x=x.x*y.x;
114 return a;
115 }
116
117 friend bigfloat operator*(const bigfloat& x, const unsigned long y) {
118 bigfloat a;
119 a.x=x.x*y;
120 return a;
121 }
122
123 friend bigfloat operator/(const bigfloat& x, const bigfloat& y){
124 bigfloat a;
125 a.x=x.x/y.x;
126 return a;
127 }
128
129 friend bigfloat operator/(const unsigned long x, const bigfloat& y){
130 bigfloat bx(x);
131 return bx/y;
132 }
133
134 friend bigfloat operator/(const bigfloat& x, const unsigned long y){
135 bigfloat by(y);
136 return x/by;
137 }
138
139 friend bigfloat sqrt_bf(const bigfloat& x){
140 bigfloat a;
141 a.x= sqrt(x.x);
142 return a;
143 }
144
145 friend bigfloat sqrt_bf(const unsigned long x){
146 bigfloat a(x);
147 return sqrt_bf(a);
148 }
149
150 friend bigfloat abs_bf(const bigfloat& x){
151 bigfloat a;
152 a.x=fabs(x.x);
153 return a;
154 }
155
156 friend bigfloat pow_bf(const bigfloat& a, long power) {
157 bigfloat b;
158 b.x=pow(a.x,power);
159 return b;
160 }
161
162 friend bigfloat pow_bf(const bigfloat& a, bigfloat &power) {
163 bigfloat b;
164 b.x=pow(a.x,power.x);
165 return b;
166 }
167
168 friend bigfloat exp_bf(const bigfloat& a) {
169 bigfloat b;
170 b.x=exp(a.x);
171 return b;
172 }
173
174 /* Comparison Functions */
175 friend int operator>(const bigfloat& x, const bigfloat& y) {
176 return x.x>y.x;
177 }
178
179 friend int operator<(const bigfloat& x, const bigfloat& y) {
180 return x.x<y.x;
181 }
182
183 friend int sgn(const bigfloat& x) {
184 if ( x.x>=0 ) return 1;
185 else return 0;
186 }
187
188 /* Miscellaneous Functions */
189
190 // friend bigfloat& random(void);
191};
192
193#endif
194
195
accelerator_inline Grid_simd< S, V > exp(const Grid_simd< S, V > &r)
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
Lattice< obj > pow(const Lattice< obj > &rhs_i, RealD y)
double mfloat
friend bigfloat operator/(const bigfloat &x, const bigfloat &y)
friend bigfloat operator-(const bigfloat &x, const bigfloat &y)
friend bigfloat operator/(const unsigned long x, const bigfloat &y)
friend bigfloat operator/(const bigfloat &x, const unsigned long y)
bigfloat(const char *str)
friend int operator>(const bigfloat &x, const bigfloat &y)
bigfloat & operator+=(const bigfloat &y)
bigfloat & operator/=(const bigfloat &y)
bigfloat(const double d)
friend bigfloat operator+(const bigfloat &x, const unsigned long y)
bigfloat(const int i)
bigfloat & operator*=(const bigfloat &y)
friend bigfloat pow_bf(const bigfloat &a, long power)
bigfloat(const float d)
bigfloat & operator=(const double y)
friend bigfloat operator-(const bigfloat &x)
friend int sgn(const bigfloat &x)
friend bigfloat sqrt_bf(const unsigned long x)
size_t read(void)
size_t write(void)
bigfloat & operator-=(const bigfloat &y)
friend bigfloat operator-(const bigfloat &x, const unsigned long y)
friend bigfloat exp_bf(const bigfloat &a)
~bigfloat(void)
friend bigfloat abs_bf(const bigfloat &x)
void setPrecision(unsigned long dprec)
bigfloat & operator=(const signed long y)
bigfloat(const long i)
friend bigfloat operator*(const bigfloat &x, const unsigned long y)
unsigned long getPrecision(void) const
bigfloat & operator=(const bigfloat &y)
friend bigfloat sqrt_bf(const bigfloat &x)
mpf_t x
Definition bigfloat.h:23
static void setDefaultPrecision(unsigned long dprec)
friend int operator<(const bigfloat &x, const bigfloat &y)
bigfloat(const bigfloat &y)
unsigned long getDefaultPrecision(void) const
friend bigfloat operator-(const unsigned long x, const bigfloat &y)
friend bigfloat operator*(const bigfloat &x, const bigfloat &y)
bigfloat & operator=(const float y)
friend bigfloat pow_bf(const bigfloat &a, bigfloat &power)
friend bigfloat operator+(const bigfloat &x, const bigfloat &y)
bigfloat(const unsigned long u)
bigfloat & operator=(const unsigned long y)