- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I wrote the following test program
int main() {
double a;
cin >> a;
float b = a;
cout << a << endl;
}
When I input 3.88e+308, the same comes as output. Isn't this much larger than the maximum representable value for a float? Does the compiler just take care of this for me, i.e. do I ever have to worry about anything other than loss of precision when converting doubles to floats?
Thanks,
~Nafis
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you intend to display the value of b? Are you using a 32-bit ICL, in which case the result might be affected by whether you use an SSE2 option (-xW et al) or a -fp-port option, including -Op or -fp:precise? Translate those if you are using linux C++.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oops --I had been awake for 48 hours straight when I wrote that.Yes, I meant to display b, and it prints as infinity. A more general question, then. Is there a standard way in C++ to make sure that a double isn't too small or too big to fit into a float? Thanks,
~Nafis
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page