uber / h3

Hexagonal hierarchical geospatial indexing system
https://h3geo.org
Apache License 2.0
4.95k stars 470 forks source link

Compute constants at start of program #912

Closed heshpdx closed 2 months ago

heshpdx commented 2 months ago

Instead of using #defined constants, we can use static const variables that lets the system compute what the values would be. This puts to bed any debate around accuracy and rounding and if we added enough significant figures into the definition. What is one-third anyway? Just let the system decide...

(gdb) p (double) 1/3
$1 = 0.33333333333333331

Ideally we would want to use constexpr instead of const, because constexpr is evaluated at compile time. But constexpr is only available in C++. const is evaluated at the beginning of runtime. What I don't know is how often does a program start up in the field? If it is very frequent then maybe this is not a good idea.

heshpdx commented 2 months ago

Understood! I will close this PR.