long b = 99;
float c = 99.0F;
//b = c; //Error : Cannot implicitly convert type 'float' to 'long'.
c = b; // Running Successfully. Why?
Why is there no problem regarding size of data type and implicitly converting?
The size of float
and long
is different as we know and which is given below...
Console.WriteLine("Long : " + sizeof(long)); // Output --> Long : 8
Console.WriteLine("Float : " + sizeof(float));// Output --> Float: 4
long represent Int64 type i.e an integral number while float represents Single type i.e a floating point number. And even though the size of long is larger than that of float, it is not possible to convert from a float to an integer without loosing information. For more information on long and float type refer msdn.
From float to long you could lose all behind the floating point so there will be no implicit cast because normally you do not want to lose this information. You may well lose information going from long to float .
The long float is a K&R C first edition type that existed. It is synonymous with double . After the first standard C89/C90, long float is removed. It is not deprecated.
long (in c) is equivalent to long int . The size of this type varies between processors and compilers, but is often, as you say, 32 bits. At 32 bits, it can represent 232 different values. Since we often want to use negative numbers, computers normally represent integers using a format called "two's complement".
A float's range (approx ±3.4e38) is much larger than a long's range (approx. ±9.22e18), even though a long has higher precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With