Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Derivation of the 0x9E3779B97F4A7C17u constant
#include <cmath> #include <cstdint> #include <ios> #include <iostream> std::uint64_t next_odd(const std::uint64_t x) { return (x % 2 == 0) ? x + 1 : x; } int main() { const long double num = std::pow(2.0l, 64.0l); const long double phi = 1.61803398874989484820459l; // (1 + sqrt(5)) / 2 const long double x = num / phi; const std::uint64_t y = next_odd(static_cast<std::uint64_t>(x)); std::cout << "0x" << std::hex << std::uppercase << y << "u" << std::endl; }
run
|
edit
|
history
|
help
0
Union-Struct-uint32_t byte order
Assignment Operator Example
mpi_distributed_sort
user defined exception
Merge Sort
marquee text in C++
SimpleList Example
pointer to pointer
template specialization inheritance problem
std::function copies