Casting to an int will truncate toward zero. floor()
will truncate toward negative infinite. This will give you different values if bar
were negative.
More Related Contents:
- How do I print a double value with full precision using cout?
- round() for float in C++
- Floating point vs integer calculations on modern hardware
- Sin and Cos give unexpected results for well-known angles
- Dealing with accuracy problems in floating-point numbers
- Efficient implementation of log2(__m256d) in AVX2
- Should I use double or float?
- Why is my integer math with std::pow giving the wrong answer?
- C++ decimal data types
- How to check if C++ compiler uses IEEE 754 floating point standard
- Floating point comparison revisited
- Building a 32-bit float out of its 4 composite bytes
- Why does Clang optimize away x * 1.0 but NOT x + 0.0?
- How computer does floating point arithmetic?
- How to correctly and standardly compare floats?
- Convert a float to a string
- Math precision requirements of C and C++ standard
- Should we generally use float literals for floats instead of the simpler double literals?
- printf rounding behavior for doubles
- C++ floating point to integer type conversions
- Check double variable if it contains an integer, and not floating point
- Why is there no 2-byte float and does an implementation already exist?
- How to write a Float Mat to a file in OpenCV
- Does one double promote every int in the equation to double?
- Handling overflow when casting doubles to integers in C
- When a float variable goes out of the float limits, what happens?
- Why isn’t “0f” treated as a floating point literal in C++?
- How is floating point conversion actually done in C++?(double to float or float to double)
- How to force GCC to assume that a floating-point expression is non-negative?
- Is there any advantage to using pow(x,2) instead of x*x, with x double?