Search Postgresql Archives

Re: Strange results when casting string to double

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 






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





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux