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
Thread-safe Interval Average Calculator
problem_name_1
Argument passing by using reference and value
Variadic Template: Make Index Sequence
Member inheritance
UTF-8 in C++11
C++ Register
NaN inside set
AnnotateAttr templated test
Recursive Function Calling Example with Stack Addresses