use thread-local storage for constant caches
also use tls for bernoulli numbers