M
mathieu
Hi,
I am working on an IO library, and I am reading a binary blob which
represent a floating point. I would like to know what is the correct
way to interpret it. For integer type using a stringstream works like
a charm, but for floating point I am getting a behavior that I don't
quite understand, for instance (*).
BTW NaN is the IEEE with all bit set, right ? What is the
representation for infinity ?
Thanks !
-Mathieu
(*)
#include <limits>
#include <iostream>
#include <sstream>
int main()
{
double inf = std::numeric_limits<double>::infinity();
//double nan = std::numeric_limits<double>::quiet_NaN();
std::cout << inf << std::endl;
std::cout << nan << std::endl;
std::stringstream ss;
ss << inf;
double out;
ss >> out;
std::cout << out << std::endl;
return 0;
}
returns:
inf
nan
4.86135e-270
I am working on an IO library, and I am reading a binary blob which
represent a floating point. I would like to know what is the correct
way to interpret it. For integer type using a stringstream works like
a charm, but for floating point I am getting a behavior that I don't
quite understand, for instance (*).
BTW NaN is the IEEE with all bit set, right ? What is the
representation for infinity ?
Thanks !
-Mathieu
(*)
#include <limits>
#include <iostream>
#include <sstream>
int main()
{
double inf = std::numeric_limits<double>::infinity();
//double nan = std::numeric_limits<double>::quiet_NaN();
std::cout << inf << std::endl;
std::cout << nan << std::endl;
std::stringstream ss;
ss << inf;
double out;
ss >> out;
std::cout << out << std::endl;
return 0;
}
returns:
inf
nan
4.86135e-270