Skip to content

Instantly share code, notes, and snippets.

@codec-abc
Last active August 6, 2018 19:20
Show Gist options
  • Select an option

  • Save codec-abc/974fb7c7e39e445d238acecf51080cf2 to your computer and use it in GitHub Desktop.

Select an option

Save codec-abc/974fb7c7e39e445d238acecf51080cf2 to your computer and use it in GitHub Desktop.
// Example program
#include <iostream>
#include <string>
#include <limits>
int main()
{
float x = std::numeric_limits<float>::max() / 1.5f;
float y = x;
float sum = x + y;
float m_x = -x;
float m_y = -y;
float m_sum = m_x + m_y;
float sum2 = sum + m_sum;
std::cout << "max float is " << std::numeric_limits<float>::max() << std::endl;
std::cout << "x " << x << std::endl;
std::cout << "y " << y << std::endl;
std::cout << "sum " << sum << std::endl;
std::cout << "-x " << m_x << std::endl;
std::cout << "-y " << m_y << std::endl;
std::cout << "(-x) + (-y) " << m_sum << std::endl;
std::cout << "sum + (-sum) " << sum2 << std::endl;
}
/* prints
max float is 3.40282e+38
x 2.26855e+38
y 2.26855e+38
sum inf
-x -2.26855e+38
-y -2.26855e+38
(-x) + (-y) -inf
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment