Re: Strange results when casting string to double - Mailing list pgsql-general

From Carsten Klein
Subject Re: Strange results when casting string to double
Date
Msg-id 4592fac1-05b2-f775-3332-c5a7d4c65b9d@datagis.com
Whole thread Raw
In response to Re: Strange results when casting string to double  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
Responses Re: Strange results when casting string to double
List pgsql-general


On 18.02.2022 13:28, Peter Eisentraut wrote:

> float8in() really just calls the operating system's strtod() function. I 
> would test that one directly with a small C program.
> 
> It's also possible that different compiler options lead to different 
> optimizations.

That's what I did. Here's my small C program: (nicht lachen *g*)

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {

     /* default string to convert */
     char buf[10] = "1.56\0";

     /* choose and print string to convert */
     char* sval = argc > 1 ? argv[1] : buf;
     printf("string value: %s\n", sval);

     /* convert and print */
     char* ptr;
     double dval = strtod(sval, &ptr);
     printf("double value: %.20f\n", dval);

     return 0;
}

It works correctly on all these servers. Here's its output:

string value: 1.56
double value: 1.56000000000000005329

I didn't test different compiler options. However, PostgreSQL was always 
installed from official Ubuntu 14.04 repositories (getting the binaries, 
not the source packages), so all binaries should have been compiled with 
the same options.

Carsten



pgsql-general by date:

Previous
From: Mladen Gogala
Date:
Subject: Re: 2 phase commit with FDW
Next
From: Laura Smith
Date:
Subject: UUID type question