Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 bjornp   Members   -  Reputation: 185

Like
0Likes
Like

Posted 27 April 2014 - 01:44 AM

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.


Sponsor:

#2 bjornp   Members   -  Reputation: 185

Like
0Likes
Like

Posted 27 April 2014 - 01:49 AM

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



#3 BitMaster   Crossbones+   -  Reputation: 3771

Like
0Likes
Like

Posted 27 April 2014 - 04:40 AM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS