CCoord gencoord(void ) { static int counter=0; CCoord loc_coord(counter, rand()/MyFloat(RAND_MAX), rand()/MyFloat(RAND_MAX), rand()/MyFloat(RAND_MAX)); /*CCoord loc_coord(counter, counter, counter, counter);*/ counter++; return loc_coord; };
void read_ascii_vecn(string fname,string fwname, typeVecData *data, int n=6) { (*data).clear(); std::ifstream fin(fname.c_str()); std::ifstream fwin(fwname.c_str()); unsigned int i=0; srand(100); CCoord t(i,0,0,0); while(!fin.eof()) { fin>>t.pos[0]; fin>>t.pos[1]; fin>>t.pos[2]; fin>>t.vel[0]; fin>>t.vel[1]; fin>>t.vel[2]; fwin>>t.w; t.id=i; if(rand()/MyFloat(RAND_MAX) < RAND_FRACTION) (*data).push_back( t); i++; } fin.close(); fwin.close(); cout<<"Got Np= "<<(*data).size()<<endl; }
MyFloat MyFloat::operator+(const MyFloat& rhs) const{ MyFloat copy_1 = MyFloat(*this); MyFloat copy_2 = MyFloat(rhs); // 1.mantissa add the 1 copy_1.mantissa += 0x800000; copy_2.mantissa += 0x800000; // leave a space for subtraction in lsb copy_1.mantissa <<= 1; copy_2.mantissa <<= 1; copy_2.exponent--; copy_1.exponent--; // Shift everything to the right until the two exponents are equal while(copy_1.exponent != copy_2.exponent) { if(copy_1.exponent > copy_2.exponent) { copy_2.exponent++; copy_2.mantissa = copy_2.mantissa >> 1; } else {
void read_ascii_vec(string fname, vector<MyFloat> *data) { (*data).clear(); std::ifstream fin(fname.c_str()); double x; unsigned int i=0; srand(100); while(!fin.eof()) { fin>>x; if(rand()/MyFloat(RAND_MAX) < 0.20) (*data).push_back( x); i++; } fin.close(); }
void read_ascii(string fname, typeVecData *data) { (*data).clear(); std::ifstream fin(fname.c_str()); double x, y, z; unsigned int i=0; srand(100); while(!fin.eof()) { fin>>x>>y>>z; if(rand()/MyFloat(RAND_MAX) < 0.20) (*data).push_back(CCoord(i, x, y, z)); i++; } fin.close(); }
//Relies on operator+ simply flips the sign of the second argument. MyFloat MyFloat::operator-(const MyFloat& rhs) const{ MyFloat copy = MyFloat(rhs); copy.sign = !(bool)(copy.sign); //Flip sign for subtraction return *this + copy; }
//comparison bool MyFloat::operator==(const float rhs) const { MyFloat f_cmp = MyFloat(rhs); if( this->sign == f_cmp.sign && this->exponent == f_cmp.exponent && this->mantissa == f_cmp.mantissa) return true; return false; }