Re: Unsigned 64 bit integer to numeric

Поиск
Список
Период
Сортировка
От Dmitry Dolgov
Тема Re: Unsigned 64 bit integer to numeric
Дата
Msg-id 20191204192537.nbhjnvtcz4b2brub@localhost
обсуждение исходный текст
Ответ на Re: Unsigned 64 bit integer to numeric  (Andrew Gierth <andrew@tao11.riddles.org.uk>)
Список pgsql-hackers
> On Wed, Dec 04, 2019 at 11:49:20AM +0000, Andrew Gierth wrote:
>
> >>>>> "Dmitry" == Dmitry Dolgov <9erthalion6@gmail.com> writes:
>
>  Dmitry> Hi,
>
>  Dmitry> Probably a simple question, but I don't see a simple answer so
>  Dmitry> far. In one extension I want to convert uint64 into a numeric
>  Dmitry> to put it eventually into a jsonb object. As far as I see in
>  Dmitry> numeric.c there are functions only for signed int64. Is there a
>  Dmitry> way to achive this with uint64 (without duplicating significant
>  Dmitry> part of numeric implementation in the extension)?
>
> Sure. Flip the top bit; convert the value as if signed; then subtract
> -(2^63) from the result. (Easier to subtract -(2^63) than to add 2^63,
> since the former can itself be represented in a signed int64 for easy
> conversion to numeric.)

Indeed, looks like this does the trick, thank you!



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

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: [HACKERS] Block level parallel vacuum
Следующее
От: Andres Freund
Дата:
Сообщение: Re: Why JIT speed improvement is so modest?