Advertisement

[Solved] Need help with a warning when compiling Double to float, loss of data

Started by April 27, 2014 07:44 AM
1 comment, last by BitMaster 10 years, 9 months ago

Hello, I get a warning when comiling my project. The project works as intended but would be nice to resolve the warning.

It says:


warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data

for each of these lines


DirectX::XMMATRIX rotationMatrix = DirectX::XMMatrixRotationY(0.5f*DirectX::XM_PI);
Eye = DirectX::XMVectorSet( x, 3.0f, z, 0.0f );
At = DirectX::XMVectorSet( x + sin(CameraRotationHorizontal), 3.0f,z + cos(CameraRotationHorizontal), 0.0f );

they are declared as the following types


DirectX::XMVECTOR Eye;
DirectX::XMVECTOR At;
DirectX::XMMATRIX rotationMatrix
How do I solve these? They're all predefined types from the DirectX API with their assosciated functions, not sure what i can do here.

Never mind, solved it by changing x and z to float instead of double.

Advertisement

I cannot comment that particular piece of code but there are valid reasons for converting a double into a float. When doing so you need to tell your compiler you really mean that since there is a loss of information:

myFloat = static_cast<float>(myDouble);

This topic is closed to new replies.

Advertisement