pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Roman Kononov <kononov195-pgsql@yahoo.com>
To: Bruce Momjian <bruce@momjian.us>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org, PostgreSQL-patches <pgsql-patches@postgresql.org>
Cc: Roman Kononov <kononov195-pgsql@yahoo.com>
Subject: Re: [HACKERS] [BUGS] BUG #2846: inconsistent and confusing
Date: Fri, 29 Dec 2006 11:11:29 -0600
Message-ID: <45954C41.8020304@yahoo.com> (raw)
In-Reply-To: <200612290623.kBT6Nnh18012@momjian.us>
References: <200612290623.kBT6Nnh18012@momjian.us>

On 12/29/2006 12:23 AM, Bruce Momjian wrote:
> Well, then show me what direction you think is better.

Think about this idea please. This has no INF, NaN or range
checks and detects all "bad" cases with any floating point
math.

The only issue is that a bad case is detected only once.
You need to restart the postmaster. It can be fixed by
re-enabling FP exceptions in the FP exception handler.

Roman
-----------------------------
~/postgresql-8.2.0/src/backend/utils/adt>diff -U3 -p float.orig.c float.c
--- float.orig.c        2006-12-29 10:49:51.000000000 -0600
+++ float.c     2006-12-29 10:58:19.000000000 -0600
@@ -60,12 +60,21 @@
  #ifdef HAVE_IEEEFP_H
  #include <ieeefp.h>
  #endif
+#include <fenv.h>

  #include "catalog/pg_type.h"
  #include "libpq/pqformat.h"
  #include "utils/array.h"
  #include "utils/builtins.h"

+static void __attribute__((__constructor__))
+enable_fp_exceptions()
+{
+       feclearexcept(FE_ALL_EXCEPT);
+       feenableexcept(FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID);
+       printf("FP exceptions enabled\n");
+}
+

  #ifndef M_PI
  /* from my RH5.2 gcc math.h file - thomas 2000-04-03 */
@@ -783,11 +792,10 @@ float4pl(PG_FUNCTION_ARGS)
  {
         float4          arg1 = PG_GETARG_FLOAT4(0);
         float4          arg2 = PG_GETARG_FLOAT4(1);
-       double          result;
+       float4          result;

         result = arg1 + arg2;
-       CheckFloat4Val(result);
-       PG_RETURN_FLOAT4((float4) result);
+       PG_RETURN_FLOAT4(result);
  }

  Datum
@@ -795,11 +803,10 @@ float4mi(PG_FUNCTION_ARGS)
  {
         float4          arg1 = PG_GETARG_FLOAT4(0);
         float4          arg2 = PG_GETARG_FLOAT4(1);
-       double          result;
+       float4          result;

         result = arg1 - arg2;
-       CheckFloat4Val(result);
-       PG_RETURN_FLOAT4((float4) result);
+       PG_RETURN_FLOAT4(result);
  }

  Datum
@@ -807,11 +814,10 @@ float4mul(PG_FUNCTION_ARGS)
  {
         float4          arg1 = PG_GETARG_FLOAT4(0);
         float4          arg2 = PG_GETARG_FLOAT4(1);
-       double          result;
+       float4          result;

         result = arg1 * arg2;
-       CheckFloat4Val(result);
-       PG_RETURN_FLOAT4((float4) result);
+       PG_RETURN_FLOAT4(result);
  }

  Datum
@@ -819,18 +825,10 @@ float4div(PG_FUNCTION_ARGS)
  {
         float4          arg1 = PG_GETARG_FLOAT4(0);
         float4          arg2 = PG_GETARG_FLOAT4(1);
-       double          result;
-
-       if (arg2 == 0.0)
-               ereport(ERROR,
-                               (errcode(ERRCODE_DIVISION_BY_ZERO),
-                                errmsg("division by zero")));
-
-       /* Do division in float8, then check for overflow */
-       result = (float8) arg1 / (float8) arg2;
+       float4          result;

-       CheckFloat4Val(result);
-       PG_RETURN_FLOAT4((float4) result);
+       result = arg1 / arg2;
+       PG_RETURN_FLOAT4(result);
  }

  /*




view thread (10+ messages)  latest in thread

Message-ID: <45954C41.8020304@yahoo.com>
Permalink:  ../45954C41.8020304@yahoo.com/
Also on:    postgresql.org/message-id/45954C41.8020304@yahoo.com

 · 

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: kononov195-pgsql@yahoo.com, bruce@momjian.us, tgl@sss.pgh.pa.us, pgsql-patches@postgresql.org
  Subject: Re: [HACKERS] [BUGS] BUG #2846: inconsistent and confusing
  In-Reply-To: <45954C41.8020304@yahoo.com>

* 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