Fixed floating point exception in long=>numeric conversion.
authorMichael Meskes <meskes@postgresql.org>
Tue, 7 Oct 2003 18:36:46 +0000 (18:36 +0000)
committerMichael Meskes <meskes@postgresql.org>
Tue, 7 Oct 2003 18:36:46 +0000 (18:36 +0000)
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/pgtypeslib/numeric.c

index ce7fe1e7111b492395cb2246a008b1f03670c697..1bea5b8e22b6736fc4cfa6e9af8cd0ad2722732c 100644 (file)
@@ -1679,6 +1679,10 @@ Mon Oct  6 08:41:45 CEST 2003
 Tue Oct  7 07:45:09 CEST 2003
 
        - Fixed error handling in rstrdate.
+       
+Tue Oct  7 20:26:06 CEST 2003
+
+       - Fixed floating point exception in long=>numeric transformation.
        - Set ecpg version to 3.0.0
        - Set ecpg library to 4.0.0
        - Set pgtypes library to 1.0.0
index 569bcb23b4f2207cef0ba33a31b547a4214248df..872d2e69e7783b373cbb23203bd4154ad5e72d5c 100644 (file)
@@ -1338,6 +1338,7 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
        signed long int extract;
        signed long int reach_limit;
 
+       printf("l=%ld\n", long_val);
        if (abs_long_val < 0)
        {
                abs_long_val *= -1;
@@ -1351,10 +1352,19 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
        {
                size++;
                reach_limit *= 10;
-       } while ((reach_limit - 1) < abs_long_val);
+       } while ((reach_limit - 1) < abs_long_val && reach_limit <= LONG_MAX/10);
 
-       /* always add a .0 */
-       size++;
+       if (reach_limit <= LONG_MAX/10)
+       {
+               /* add the first digit and a .0 */
+               size += 2;
+       }
+       else
+       {
+               /* always add a .0 */
+               size++;
+               reach_limit /= 10;
+       }
 
        if (alloc_var(var, size) < 0)
                return -1;
@@ -1366,11 +1376,11 @@ PGTYPESnumeric_from_long(signed long int long_val, numeric *var)
        i = 0;
        do
        {
-               reach_limit /= 10;
                extract = abs_long_val - (abs_long_val % reach_limit);
                var->digits[i] = extract / reach_limit;
                abs_long_val -= extract;
                i++;
+               reach_limit /= 10;
 
                /*
                 * we can abandon if abs_long_val reaches 0, because the memory is