From: | Roman Kononov <kononov195-pgsql(at)yahoo(dot)com> |
---|---|
To: | Bruce Momjian <bruce(at)momjian(dot)us> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>, Roman Kononov <kononov195-pgsql(at)yahoo(dot)com> |
Subject: | Re: [HACKERS] [BUGS] BUG #2846: inconsistent and confusing |
Date: | 2006-12-29 17:11:29 |
Message-ID: | 45954C41.8020304@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
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);
}
/*
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-12-29 17:21:56 | Re: [HACKERS] Bundle of patches |
Previous Message | mark | 2006-12-29 17:08:07 | Re: TODO: GNU TLS |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-12-29 17:21:56 | Re: [HACKERS] Bundle of patches |
Previous Message | Tom Lane | 2006-12-29 16:52:05 | Re: [PATCHES] [BUGS] BUG #2846: inconsistent and |