I have the following code that works in case (2) but not in case (1). Can anyone explain this to me? This could be the cause of many of my more subtle bugs.
int main()
{
sf::Window gameWindow(sf::VideoMode::GetMode(0), "Block Buster",sf::Style::Fullscreen);
uint32_t VideoModesCount = sf::VideoMode::GetModesCount();
for(uint32_t i = 0; i < VideoModesCount; ++i)
{
sf::VideoMode Mode = sf::VideoMode::GetMode(i);
float sixteenByNine = (float)16/9;
float aspectRatio = (float)Mode.Width / Mode.Height;
(1) if((float)((float)Mode.Width / Mode.Height) == ((float)16/9))
(2) if(aspectRatio == sixteenByNine)
std::cout << "Video Mode " << i << ":\tWidth: " << Mode.Width
<<"\tHeight: " << Mode.Height << "\tBpp: " << Mode.BitsPerPixel
<< std::endl;
}
// ...
return EXIT_SUCCESS;
}
Is there some weird truncation that is happening when I am directly comparing the variables inside the if() statement?
Thanks for your help.
- Dave Ottley