pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Nathan Bossart <nathandbossart@gmail.com>
To: Joseph Koshakow <koshy44@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Subject: Re: Remove dependence on integer wrapping
Date: Mon, 15 Jul 2024 10:31:08 -0500
Message-ID: <ZpVAvLbtUPnK1JKe@nathan> (raw )
In-Reply-To: <CAAvxfHdX-t03LvxROxbyodBrtzBzZQEKdKB0FCpEr+p1JnFxsA@mail.gmail.com >
References: <ZmZbXK1CNMbkty0W@nathan >
<618777.1717984674@sss.pgh.pa.us >
<31ad2cd1-db94-bdb3-f91a-65ffdb4bef95@gmail.com >
<CAAvxfHfqJca-WGvWJQ3ZAtt2po=mkQzU8r9Qjzom4YqxQi84oA@mail.gmail.com >
<CAAvxfHdhEz4eF7z1wNn_4C4Gkt+e-h7OjzKUJXt7CE+CvubqcQ@mail.gmail.com >
<CAAvxfHdze21+UZPWo7ePfH19-9hvXe_9SEZk4HABPHuzaUitRQ@mail.gmail.com >
<CAAvxfHd22ujbY6uTraE+ZSTUN0xX0G-=NZcr0YnKSQuXthcM+g@mail.gmail.com >
<CAAvxfHcDQEziyQ-ehv0Bg05OovGPGO95VoO7-DyxJx6Tkq85vA@mail.gmail.com >
<ZpFeopUrhdB5GgNN@nathan >
<CAAvxfHdX-t03LvxROxbyodBrtzBzZQEKdKB0FCpEr+p1JnFxsA@mail.gmail.com >
I took a closer look at 0002.
+ if (unlikely(isinf(f) || isnan(f)))
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("invalid float value")));
+
+ fresult = rint(f * c);
+ if (unlikely(f == 0.0))
+ ereport(ERROR,
+ (errcode(ERRCODE_DIVISION_BY_ZERO),
+ errmsg("division by zero")));
+ if (unlikely(isinf(f) || isnan(f)))
+ ereport(ERROR,
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("invalid float value")));
+
+ fresult = rint(c / f);
I'm curious why you aren't using float8_mul/float8_div here, i.e.,
fresult = rint(float8_mul((float8) c, f));
fresult = rint(float8_div((float8) c, f));
nitpick: I'd name the functions something like "cash_mul_float8" and
"cash_div_float8". Perhaps we could also add functions like
"cash_mul_int64" and "cash_sub_int64" so that we don't need several copies
of the same "money out of range" ERROR.
--
nathan
view thread (85+ messages) latest in thread
Message-ID: <ZpVAvLbtUPnK1JKe@nathan>
Permalink: ../ZpVAvLbtUPnK1JKe@nathan/
Also on: postgresql.org/message-id/ZpVAvLbtUPnK1JKe@nathan
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, koshy44@gmail.com, exclusion@gmail.com, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org, andres@anarazel.de
Subject: Re: Remove dependence on integer wrapping
In-Reply-To: <ZpVAvLbtUPnK1JKe@nathan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox