Re: Remove dependence on integer wrapping - Mailing list pgsql-hackers

From Nathan Bossart
Subject Re: Remove dependence on integer wrapping
Date
Msg-id ZpVAvLbtUPnK1JKe@nathan
Whole thread Raw
In response to Re: Remove dependence on integer wrapping  (Joseph Koshakow <koshy44@gmail.com>)
Responses Re: Remove dependence on integer wrapping
List 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



pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Incremental backup from a streaming replication standby fails
Next
From: Andres Freund
Date:
Subject: Re: gcc 12.1.0 warning