Conversion from unsigned int to float

T.T*_*.T. 5 c++ windows variables types

warning C4244: '=' : conversion from 'unsigned int' to 'float', possible loss of data  
Run Code Online (Sandbox Code Playgroud)

Shouldn't a float be able to handle any value from an int?

unsigned int: 0 to 4,294,967,295  
float 3.4E +/- 38 (7 digits) 
Run Code Online (Sandbox Code Playgroud)

Wiki:

The advantage of floating-point representation over fixed-point (and
Run Code Online (Sandbox Code Playgroud)

integer) representation is that it can support a much wider range of values.

Any insight would be helpful, thanks.

http://msdn.microsoft.com/en-us/library/s3f49ktz%28VS.80%29.aspx

Jar*_*ger 12

'unsigned int'和'float'都使用32位来存储值.由于浮子的范围较大,因此必然会牺牲一些精度.这意味着有一些无符号的int值无法在float中准确表示.MSDN提供了一些更多细节.


Dou*_*rch 7

While float supports a wider range of values than unsigned int, it does so with less accuracy. Floats have a 23-bit mantissa which, as you posted, is only about 7 decimal digits. unsigned ints support over 9 decimal digits.

Suggestion: use double, not float.

Edit: Actually, I retract that suggestion; floating-point and integer data types are fundamentally different and are not directly convertible. What integer value do you expect to get for Single.MaxValue? For Single.NegativeInfinity? Explaining why you want to convert from float to int would be helpful.