// the following code works as expected
std::cout << std::numeric_limits<unsigned int>::max() << std::endl; // yields 4294967295, the largest
std::cout << std::pow(2, 8 * sizeof(unsigned int)) << std::endl; // yields 4294967296
std::cout << static_cast<unsigned int>(std::pow(2, 8 * sizeof(unsigned int))) << std::endl; // yields 0, because of modulo the largest + 1
std::cout << static_cast<unsigned int>(std::pow(2, 8 * sizeof(unsigned int))*3 + 1) << std::endl; // yields 1, because of modulo the largest + 1
// working on 64bit windows with VS2019, C++
std::cout << std::numeric_limits<size_t>::max() << std::endl; // yields 18446744073709551615, the largest, fine
std::cout << std::pow(2, 8 * sizeof(size_t)) << std::endl; // yields 18446744073709551616, fine
// now the unexpected happens. My question is why?
std::cout << static_cast<size_t>(std::pow(2, 8 * sizeof(size_t))) << std::endl; // yields 9223372036854775808 but should yield 0, because of modulo the largest + 1
std::cout << static_cast<size_t>(std::pow(2, 8 * sizeof(size_t))*3 + 1) << std::endl; // yields 9223372036854775808 but should yield 1, because of modulo the largest + 1
// whereby maybe worth to mention 9223372036854775808 is exactly half of 18446744073709551616.
// and by the way, clang produced 0 for both answers.