Re: rounding_up

From: Daria Shanina <vilensipkdm(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Christoph Moench-Tegeder <cmt(at)burggraben(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: rounding_up
Date: 2025-04-14 14:55:17
Message-ID: CAMp4U1cAEFsXMJhBOuCsR0=QRxePs1DQUEK_igwQh4ddpZx8BQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Christoph!

You wrote a very interesting answer.

> First question would be "which round rule?"

I mean rounding up “as at school”, but there are nuances in programming.

> https://www.postgresql.org/docs/current/functions-math.html

Thanks a lot for the link to the doc!

> you set it to with fesetround() (see
man page)

To my great shame, I didn't know about fesetround(). Thanks a lot too!

Best regards,

Daria Shanina

пн, 14 апр. 2025 г. в 17:26, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Christoph Moench-Tegeder <cmt(at)burggraben(dot)net> writes:
> > ## Daria Shanina (vilensipkdm(at)gmail(dot)com):
> >> I noticed, when we parse and validate values (in particular, the int
> type),
> >> we use the *rint* method, but unfortunately it does not work according
> to
> >> the round rules.
>
> > First question would be "which round rule?" as (of course) there're
> > multiple to chose from.
>
> Yeah. Round-to-nearest-even is a well-respected rule, which is why
> it's the default per IEEE 754. I don't see a good reason for us
> to switch. Even if someone advanced an argument, it would have
> to be a *mighty* convincing argument to justify breaking backwards
> compatibility here.
>
> I do find it a little unfortunate that our numeric type does it
> differently than our float types. Again though, there's a huge
> compatibility argument against changing that now. It does give
> you an "out" if you really need one or the other behavior for
> a particular application: you can cast to numeric or float8
> before casting to int.
>
> regards, tom lane
>

--
С уважением,
Шанина Дарья Александровна

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Abhishek Chanda 2025-04-14 15:05:03 Re: Adding error messages to a few slash commands
Previous Message Benoit Lobréau 2025-04-14 14:41:31 Re: Logging parallel worker draught