Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "assert.h"
- #include <cmath>
- #include <limits>
- #include <sstream>
- #include <iomanip>
- #include <iostream>
- int main(int argc, char* argv[])
- {
- //testReadWrite();
- int const Prec = 35;
- double d0 = 0.0070000000000000001;
- double d1 = 0.007000000000000001;
- double d2 = 0.00700000000000001;
- //double d3 = 0.0070000000000000097;
- char buffer[100];
- std::ostringstream out;
- memset(buffer,0,sizeof(buffer));
- out.precision(Prec);
- std::string test1;
- out << d0;
- test1 = out.str();
- out << " ";
- out << d1;
- out << " ";
- out << d2;
- double d0_;
- double d1_;
- double d2_;
- std::istringstream in (out.str());
- in.precision(Prec);
- double d0X_ = strtod(test1.c_str(),NULL);
- in >> d0_;
- in >> d1_;
- in >> d2_;
- assert(d0 == d0X_); // this is ok
- assert(d0 == d0_); //this failes?!?!?!
- long long l0= *reinterpret_cast<long long *> (&d0);
- long long l1= *reinterpret_cast<long long *> (&d1);
- long long l2= *reinterpret_cast<long long *> (&d2);
- long long l0_= *reinterpret_cast<long long *> (&d0_);
- long long l1_= *reinterpret_cast<long long *> (&d1_);
- long long l2_= *reinterpret_cast<long long *> (&d2_);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement