Re: Strange results when casting string to double

From: Carsten Klein <c(dot)klein(at)datagis(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Strange results when casting string to double
Date: 2022-02-18 13:55:46
Message-ID: 4592fac1-05b2-f775-3332-c5a7d4c65b9d@datagis.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laura Smith 2022-02-18 14:06:28 UUID type question
Previous Message Mladen Gogala 2022-02-18 13:24:31 Re: 2 phase commit with FDW