From ae31b151e9a1ba8b1b17ecda07a26f3084869ed7 Mon Sep 17 00:00:00 2001 From: Jan Boon Date: Mon, 9 Feb 2026 03:27:12 +0000 Subject: [PATCH] sampling : cleaner approach for constructing floating point value --- src/llama-sampler.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/llama-sampler.cpp b/src/llama-sampler.cpp index 02258d981b..ad0a20f0ff 100644 --- a/src/llama-sampler.cpp +++ b/src/llama-sampler.cpp @@ -434,13 +434,10 @@ struct blue_noise_rng { // uniform double in [0, 1) with blue noise temporal autocorrelation double nextf() { - double res = 0.0; - res += hash(position ^ ~seed); // fill low bits with white noise - res *= 1.0 / 4294967296.0; - res += next32(); - res *= 1.0 / 4294967296.0; - if (res >= 1.0) res = std::nextafter(1.0, 0.0); - return res; + uint32_t lo = hash(position ^ ~seed); // white noise low bits + uint32_t hi = next32(); // blue noise high bits + uint64_t combined = ((uint64_t)hi << 32) | lo; + return (combined >> 11) * 0x1.0p-53; } };