/usr/include/libphylo/doubleRep.h is in rate4site 3.0.0-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | #ifndef __DOUBLE_REP_H
#define __DOUBLE_REP_H
#ifdef DOUBLEREP
#include "definitions.h"
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
/* doubleRepMantisa: enables working with much larger or smaller numbers than normally possible
by the regular double representation
* Representation of a double x as x=_mantissa*2^_expon
Note: Base is 2!!
*/
class doubleRepMantisa{
public:
doubleRepMantisa(){};
explicit doubleRepMantisa(MDOUBLE mantissa, int expon);
doubleRepMantisa(MDOUBLE a);
doubleRepMantisa(const doubleRepMantisa& other);
doubleRepMantisa* clone() {return new doubleRepMantisa(*this);}
void output(ostream &out) const{ out<<_mantissa<<string(" * 2^")<<_expon;}
// void output0x(ostream &out) const{ double e0x=_expon*0.3010299956639; // log_10(2)
// int e=(int)(trunc(e0x))-1;
// double m=_mantissa*pow(10,e0x-e);
// out<<m;
// if (e<0)
// out<<"e"<<e;
// else
// out<<"e+"<<e;
//}
void outputn(ostream &out) { out<<_mantissa<<string(" * 2^")<<_expon<<endl;}
friend MDOUBLE convert(const doubleRepMantisa& a);
inline doubleRepMantisa& operator=(const doubleRepMantisa& a);
inline doubleRepMantisa& operator+=(doubleRepMantisa a);
inline doubleRepMantisa& operator++();
inline doubleRepMantisa operator++(int);
inline doubleRepMantisa& operator--();
inline doubleRepMantisa operator--(int);
friend inline doubleRepMantisa operator+(const doubleRepMantisa& a, const doubleRepMantisa& b);
inline doubleRepMantisa& operator-=(const doubleRepMantisa& a);
friend inline doubleRepMantisa operator-(const doubleRepMantisa& a, const doubleRepMantisa& b);
inline doubleRepMantisa& operator*=(const doubleRepMantisa& a);
friend inline doubleRepMantisa operator*(const doubleRepMantisa& a, const doubleRepMantisa& b);
inline doubleRepMantisa& operator/=(const doubleRepMantisa& a);
friend inline doubleRepMantisa operator/(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline bool operator==(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline bool operator!=(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline bool operator<(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline bool operator<=(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline bool operator>(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline bool operator>=(const doubleRepMantisa& a, const doubleRepMantisa& b);
friend inline doubleRepMantisa abs(const doubleRepMantisa& d);
const MDOUBLE d_log() const;
// friend ostream& operator<<(ostream &out, const doubleRepMantisa& a);
const MDOUBLE mantissa() const {return _mantissa;}
const int expon() const {return _expon;}
private:
void fixParams();
private:
MDOUBLE _mantissa;
int _expon;
};
MDOUBLE convert(const doubleRepMantisa& a); //declaration of this function to be implemented cpp
inline doubleRepMantisa& doubleRepMantisa::operator=(const doubleRepMantisa& a){
_mantissa=a.mantissa();
_expon=a.expon();
return *this;
}
inline doubleRepMantisa& doubleRepMantisa::operator++() {
return (*this)+=1;
}
// matan:
inline doubleRepMantisa doubleRepMantisa::operator++(int) {
doubleRepMantisa ans = *this;
++(*this);
return ans;
}
// matan:
inline doubleRepMantisa& doubleRepMantisa::operator--() {
return (*this)-=1;
}
// matan:
inline doubleRepMantisa doubleRepMantisa::operator--(int) {
doubleRepMantisa ans = *this;
--(*this);
return ans;
}
// Original version by Adi Stern
inline doubleRepMantisa& doubleRepMantisa::operator+=(doubleRepMantisa a){
//ensuring that (*this) is bigger than 'a' for sake of convenience
if (a.expon()>_expon || ((a.expon()==_expon) && (a.mantissa()>_mantissa))){
MDOUBLE tmpMant=0.0; int tmpExp=0;
tmpMant=_mantissa;
tmpExp=_expon;
_mantissa=a.mantissa();
a._mantissa=tmpMant;
tmpExp=_expon;
_expon=a.expon();
a._expon=tmpExp;
}
if (a.mantissa()==0)
return *this;
if (_mantissa==0){
_mantissa=a.mantissa();
_expon=a.expon();
return *this;
}
int exp_dif = _expon-a.expon();
if (abs(exp_dif)>51){ //limit of epsilon difference
return *this;
}
_mantissa+=a.mantissa()*pow(2.0,(a.expon()-_expon)*1.0);
fixParams();
return *this;
}
inline doubleRepMantisa operator+(const doubleRepMantisa& a, const doubleRepMantisa& b){
doubleRepMantisa temp(a);
temp+=b;
return temp;
}
inline doubleRepMantisa& doubleRepMantisa::operator-=(const doubleRepMantisa& a){
doubleRepMantisa b(-a.mantissa(),a.expon());
doubleRepMantisa me(_mantissa,_expon);
me+=b;
_mantissa=me.mantissa();
_expon=me.expon();
return *this;
}
inline doubleRepMantisa operator-(const doubleRepMantisa& a, const doubleRepMantisa& b){
doubleRepMantisa temp(a);
temp-=b;
return temp;
}
inline doubleRepMantisa operator-(const doubleRepMantisa& a) {
return doubleRepMantisa(0) - a;
}
inline doubleRepMantisa& doubleRepMantisa::operator*=(const doubleRepMantisa& a){
_mantissa*=a.mantissa();
_expon+=a.expon();
fixParams();
return *this;
}
inline doubleRepMantisa operator*(const doubleRepMantisa& a, const doubleRepMantisa& b){
doubleRepMantisa temp(a);
temp*=b;
return temp;
}
inline doubleRepMantisa& doubleRepMantisa::operator/=(const doubleRepMantisa& a){
_mantissa/=a.mantissa();
_expon-=a.expon();
fixParams();
return *this;
}
inline doubleRepMantisa operator/(const doubleRepMantisa& a, const doubleRepMantisa& b){
doubleRepMantisa temp(a);
temp/=b;
return temp;
}
/************************
* Comparison operators *
************************/
inline bool operator==(const doubleRepMantisa& a, const doubleRepMantisa& b){
return (a._mantissa==b._mantissa && a._expon==b._expon);
}
inline bool operator!=(const doubleRepMantisa& a, const doubleRepMantisa& b){
return !(a==b);
}
inline bool operator<(const doubleRepMantisa& a, const doubleRepMantisa& b){
// if the numbers have opposite signs
if (a._mantissa*b._mantissa<0.0){
if (a._mantissa<b._mantissa) {return true;}
else {return false;}
}
// if the expon values are different
if (a._expon!=b._expon) {
// special case where one number is zero
if (a._mantissa == 0.0) {
if (b._mantissa > 0.0) {return true;}
else {return false;}
}
if (b._mantissa == 0.0) {
if (a._mantissa < 0.0) {return true;}
else {return false;}
}
if (a._expon<b._expon) {
if (a._mantissa > 0.0) {return true;}
else {return false;}
} else {
if (a._mantissa < 0.0) {return true;}
else {return false;}
}
// expon values are identical
} else {
return (a._mantissa < b._mantissa);
}
}
inline bool operator>(const doubleRepMantisa& a, const doubleRepMantisa& b){
// if the numbers have opposite signs
if (a._mantissa*b._mantissa<0.0){
if (a._mantissa>b._mantissa) {return true;}
else {return false;}
}
// if the expon values are different
if (a._expon!=b._expon) {
// special case where one number is zero
if (a._mantissa == 0.0) {
if (b._mantissa < 0.0) {return true;}
else {return false;}
}
if (b._mantissa == 0.0) {
if (a._mantissa > 0.0) {return true;}
else {return false;}
}
if (a._expon>b._expon) {
if (a._mantissa > 0.0) {return true;}
else {return false;}
} else {
if (a._mantissa < 0.0) {return true;}
else {return false;}
}
// expon values are identical
} else {
return (a._mantissa > b._mantissa);
}
}
inline bool operator<=(const doubleRepMantisa& a, const doubleRepMantisa& b){
return !(a>b);
}
inline bool operator>=(const doubleRepMantisa& a, const doubleRepMantisa& b){
return !(a<b);
}
ostream& operator<<(ostream &out, const doubleRepMantisa& a);
istream& operator>>(istream &in, doubleRepMantisa& a);
inline MDOUBLE log(const doubleRepMantisa& d) {return d.d_log();}
inline ostream &operator<<(ostream &out, const VdoubleRepMantisa &v){
for (int j=0;j<v.size();++j)
out<< v[j]<<" ";
out <<endl;
return(out);
}
inline ostream &operator<<(ostream &out, const VVdoubleRepMantisa &m){
for (int i=0;i<m.size();++i)
out<<m[i];
out <<endl;
return(out);
}
inline doubleRepMantisa pow(const doubleRepMantisa& d1, const doubleRepMantisa& d2) {
return doubleRepMantisa(pow(convert(d1), convert(d2)));
}
inline doubleRepMantisa abs(const doubleRepMantisa& d) {
return doubleRepMantisa(abs(d._mantissa), d._expon);
}
inline doubleRepMantisa fabs(const doubleRepMantisa& d) {
return abs(d);
}
inline doubleRepMantisa exp(const doubleRepMantisa& d) {
return doubleRepMantisa(exp(convert(d)));
}
inline doubleRepMantisa sqrt(const doubleRepMantisa& d) {
return doubleRepMantisa(sqrt(convert(d)));
}
//inline const MDOUBLE convert (const MDOUBLE d) const {return(d);}
#endif
#endif
|