Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> I just had a thought: a simpler (and probably faster and more
> accurate) solution would be to use frexp() and ldexp(), which are both
> part of C99, so ought to be OK.
Seems like a plan. We're already relying on ldexp() in pg_prng.c,
so I doubt there's a portability issue. Reading the man page for
frexp(), we might want to special-case Inf and NaN inputs to avoid
assuming what it will do with those. But that would only be needed
in the slow path where we're recovering from overflow/underflow.
regards, tom lane