• Advertisement
Sign in to follow this  

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

This topic is 1363 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement