Question:
How to convert a long double into string?
Answer:
This can be done by 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.
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.
Detailed documentation is available in the below help path:
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}