Post Go back to editing

long double conversion to const char* in BF707


a simple question ! How to convert a long double into string?

long double ld64DateTime= 25618.8983912037;

char buf[128];
u8 u8Nb = snprintf(buf, sizeof(buf), "%lf", ld64DateTime);

not working !!

I am working with BF707 and CCES 2.10.0. I tried a lot, unsuccessfully !

Please give me a hint!

Best thomas

  • Hi,

    We suspect that the issue you are facing is because the application haven't been built with -double-size-64. While care has been taken to explicitly use long-double type variables the constants are all double so don't result in the expected precision.

    It would be best to modify the projects to use -double-size-64, the project setting for this is in Properties > C/C++ Build > Settings > Tool Settings > Compiler > Processor > Double size.

    Also, we are able to convert long double into string using below code snippet in CCES, after changing double size switch to -double-size-64 in the IDE by setting Project > Properties >C/C++ Build > Settings > Tool Settings > Compiler > Processor > Double size.Please refer the attached screenshots.

    code snippet:
    #include <stdio.h>
    #include <stdlib.h>
    int main
    long double num = 25618.8983912037;
    char output[128];
    snprintf(output, 128, "%lf", num);
    printf("%s", output);
    return 0;

    The datatype long double has bit size of 64 bits and its number representation is 64-bit IEEE.

    The -double-size-64 switch promotes double to a 64-bit data type, making it equivalent to long double. This switch does not affect the sizes of float or long double.

    Please refer the below CCES help path for more details.
    CrossCore® Embedded Studio <version> > Blackfin® Development Tools Documentation > C/C++ Compiler and Library Manual for Blackfin® Processors > Compiler > Compiler Command-Line Interface > C/C++ Compiler Command-Line Switches > C/C++ Compiler Common Switch Descriptions > -double-size-{32 | 64}