Re: Remove dependence on integer wrapping

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Joseph Koshakow <koshy44(at)gmail(dot)com>
Cc: Alexander Lakhin <exclusion(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Remove dependence on integer wrapping
Date: 2024-07-15 15:31:08
Message-ID: ZpVAvLbtUPnK1JKe@nathan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-07-15 16:41:55 Re: gcc 12.1.0 warning
Previous Message Laurenz Albe 2024-07-15 15:26:58 Re: Incremental backup from a streaming replication standby fails