Request Short Link
C++ 98
C++ 11
C++ 14
C++ 17
C++ 20
C++ 23
C++ 2c
for-loops as while-loops
array subscription
Show all implicit casts
Show all template parameters of a CallExpr
Use libc++
Transform std::initializer_list
Show noexcept internals
Show padding information
Show coroutine transformation
Show C++ to C transformation
Show object lifetime
Default
15
18
20
22
26
More
GitHub
Patreon
Issues
About
Policies
Examples
C++ Insights @ YouTube
Settings
Version
New C++ Insights Episode
×
Made by
Andreas Fertig
Powered by
Flask
and
CodeMirror
Source:
// Type your code here, or load an example. //double fma(double, double, double); //float fma(float, float, float); #include <cmath> #include <assert.h> void test(){ float f = 1.0f / 3.0f; double d = f; int i = 0; auto Check = [&](bool Cond) { assert(Cond); }; // f * f + 3.0f will be different if promoted to double. float floatResult = fma(f, f, 3.0f); double doubleResult = fma(d, d, 3.0); Check(floatResult != doubleResult); // check promote to float. Check(fma(f, f, 3) == floatResult); Check(fma(f, f, (char)3) == floatResult); Check(fma(f, f, (unsigned char)3) == floatResult); Check(fma(f, f, (short)3) == floatResult); Check(fma(f, f, (unsigned short)3) == floatResult); Check(fma(f, f, (int)3) == floatResult); Check(fma(f, f, (unsigned int)3) == floatResult); Check(fma(f, f, (long)3) == floatResult); Check(fma(f, f, (unsigned long)3) == floatResult); Check(fma(f, f, true) == fma(f, f, 1.0f)); // check promote to double. Check(fma(d, (double)f, 3) == doubleResult); Check(fma(d, (double)f, (char)3) == doubleResult); Check(fma(d, (double)f, (unsigned char)3) == doubleResult); Check(fma(d, (double)f, (short)3) == doubleResult); Check(fma(d, (double)f, (unsigned short)3) == doubleResult); Check(fma(d, (double)f, (int)3) == doubleResult); Check(fma(d, (double)f, (unsigned int)3) == doubleResult); Check(fma(d, (double)f, (long)3) == doubleResult); Check(fma(d, (double)f, (unsigned long)3) == doubleResult); Check(fma(d, (double)f, true) == fma((double)f, (double)f, 1.0)); }
Insight:
Console: