Re: Bug: random() can return 1.0

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Bug: random() can return 1.0
Дата
Msg-id 10560.1137713169@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Bug: random() can return 1.0  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Because random returns a double, I think it is very possible that we
> could return 1 due to rounding,

Not unless your machine has a "double" type with less than 32 bits of
precision, which seems pretty unlikely.  It'd be sufficient to do
/* result 0.0 <= x < 1.0 */result = ((double) random()) / ((double) MAX_RANDOM_VALUE + 1.0);

        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: Large Scale Aggregation (HashAgg Enhancement)
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: un-vacuum?