Double is a more precise float. C++ does not place restrictions of floating point values representation, but IEEE 754 is usually used (float is single precision and double is double precision). Actually double is usually native floating point type for modern CPU and should be used unless you have very compelling reasons to use floats instead. http://en.wikipedia.org/wiki/IEEE_floating_point
There are several integral types: char, short, int, long and long long. There is not much restrictions on them:
First of all, their relative sizes should be like this: sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(longlong)
Size of char is always 1.
Additionally there is restrictions on minimum size in bits:
I know that an int can go into a float but not the other way around
Float can go into int, but you will lose fraction part. Additionally there might be problem with very large floats being too alrge to be represented as int without overflowing.
Likewise large ints might be too unrepresentable as floats exactly (you will lose some info)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
int main() {
float f = INT_MAX;
int i = f;
if (i != INT_MAX)
std::cout << "Float loses information\n";
else
std::cout << "Float does not loses information\n";
double d = INT_MAX;
int ii = d;
if (ii != INT_MAX)
std::cout << "Double loses information\n";
else
std::cout << "Double does not loses information\n";
}
Float loses information
Double does not loses information
Any integral variable (char, short, int...) can be cast into floating point (float, double, long double) and back.
so char -> double, float -> long, etc. are possible. You just need to mind the precision when converting to floating point and range when converting to integral.