Re: [BUGS] BUG #2846: inconsistent and confusing handling of - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [BUGS] BUG #2846: inconsistent and confusing handling of
Date
Msg-id 200612272123.kBRLNdg05533@momjian.us
Whole thread Raw
Responses Re: [BUGS] BUG #2846: inconsistent and confusing handling of underflows,
List pgsql-patches
Roman Kononov wrote:
> On 12/27/2006 12:44 PM, Bruce Momjian wrote:
> > The only unsolved issue is the one with underflow checks.  I have added
> > comments explaining the problem in case someone ever figures out how to
> > address it.
>
> This will behave better for float4:
>
>     Datum float4pl(PG_FUNCTION_ARGS)
>     {
> ---    float4  arg1 = PG_GETARG_FLOAT4(0);
> ---    float4  arg2 = PG_GETARG_FLOAT4(1);
> +++    double  arg1 = PG_GETARG_FLOAT4(0);
> +++    double  arg2 = PG_GETARG_FLOAT4(1);
>         double  result;
>
>         result = arg1 + arg2;
>         CheckFloat4Val(result,isinf(arg1) || isinf(arg2));
>         PG_RETURN_FLOAT4((float4) result);
> }

Are you sure?  As I remember, computation automatically upgrades to
'double'.  See this program and output:

    $ cat tst1.c
    #include <stdio.h>
    #include <stdlib.h>

    int
    main(int argc, char *argv[])
    {
            float a = 1e30, b = 1e30;
            double c;

            c = a * b;

            printf("%e\n", c);
            return 0;
    }

    $  tst1
    1.000000e+60

--
  Bruce Momjian   bruce@momjian.us
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: Allow the identifier length to be increased via a configure option
Next
From: Bruce Momjian
Date:
Subject: Re: [BUGS] BUG #2846: inconsistent and confusing