Re: Strange results when casting string to double

Поиск
Список
Период
Сортировка
От Carsten Klein
Тема Re: Strange results when casting string to double
Дата
Msg-id 4592fac1-05b2-f775-3332-c5a7d4c65b9d@datagis.com
обсуждение исходный текст
Ответ на Re: Strange results when casting string to double  (Peter Eisentraut <peter.eisentraut@enterprisedb.com>)
Ответы Re: Strange results when casting string to double  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Mladen Gogala
Дата:
Сообщение: Re: 2 phase commit with FDW
Следующее
От: Laura Smith
Дата:
Сообщение: UUID type question