Why does NaN^0 == 1

This is referenced in the help page referenced by ?’NaN’ “The IEC 60559 standard, also known as the ANSI/IEEE 754 Floating-Point Standard. http://en.wikipedia.org/wiki/NaN.” And there you find this statement regarding what should create a NaN: “There are three kinds of operations that can return NaN:[5] Operations with a NaN as at least one operand. It … Read more

Comparison of double, long double, float and float128?

My platform does not have a __float128, but here’s an example showing output by precision with float, double, and long double: #include <cmath> #include <iomanip> #include <iostream> #include <limits> int main() { float PI0 = std::acos(-1.0F); double PI1 = std::acos(-1.0); long double PI2 = std::acos(-1.0L); constexpr auto PI0_max_digits10 = std::numeric_limits<decltype(PI0)>::max_digits10; constexpr auto PI1_max_digits10 = std::numeric_limits<decltype(PI1)>::max_digits10; … Read more

MATLAB: Is it possible to overload operators on native constructs (cells, structs, etc)?

It is in fact possible to create new operators or overload existing ones for built-in data types in MATLAB. I describe one example of this in my answer to another SO question about modifying the default overflow behavior of integer types. First, you may want to look at what methods currently exist for cell arrays. … Read more

How do promotion rules work when the signedness on either side of a binary operator differ? [duplicate]

This is outlined explicitly in ยง5/9: Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions, which are defined as … Read more