2019-07-18 05:52 AM
This :
double num= 10.85
int written = sprintf(num_buf, "%1.17g", num);
works in F4 using -u _printf_float into linker commands settings.
But does not work in H7.
Any suggestions?
2019-07-18 05:56 AM
Check what libraries you're linking.
I honestly don't understand why this is the default, and not obvious how to turn off. Generates a constant stream of queries. @Markus GIRDLAND
On a part with 512KB+ Flash and an FPU surely there's space for a properly functioning library?
2019-07-18 08:56 PM
when you select the nano library, select the nano with floating point support in Sprintf
2019-07-19 02:07 AM
@Community member What you mean for "when you select the nano library"?
Thanks
2019-07-19 04:32 AM
2019-07-19 04:43 AM
I'm usually not the guy in the meetings deciding defaults so I asked one of our developers to take a look at this.
He said it's a fair point and we should have it as default on MCUs that has a large flash. So I'll be writing a ticket for it and hopefully we can get to implementing it soon!
2019-07-19 05:15 AM
Not sure who the project/support manager is for this, or if they work the forum. Might suggest an @ TeamSTM32IDE to flag things to multiple responsible parties.
2019-07-19 06:18 AM
In the meanwhile....
int HELPER_Float_To_Char(char *str, double f, char precision)
{
long a,b,c,k,l=0,m,i=0;
// check for negative float
if(f<0.0)
{
str[i++]='-';
f*=-1;
}
a=f; // extracting whole number
f-=a; // extracting decimal part
k = precision;
// number of digits in whole number
while(k>-1)
{
l = pow(10,k);
m = a/l;
if(m>0)
{
break;
}
k--;
}
// number of digits in whole number are k+1
/*
extracting most significant digit i.e. right most digit , and concatenating to string
obtained as quotient by dividing number by 10^k where k = (number of digit -1)
*/
for(l=k+1;l>0;l--)
{
b = pow(10,l-1);
c = a/b;
str[i++]=c+48;
a%=b;
}
str[i++] = '.';
/* extracting decimal digits till precision */
for(l=0;l<precision;l++)
{
f*=10.0;
b = f;
str[i++]=b+48;
f-=b;
}
str[i]='\0';
return strlen(str);
}
2019-07-19 02:01 PM
Neat code. only looks to be 200 bytes of flash, the Nano library grows by 7k with Printf support
is that from ST, or is it self engineered ?
2019-07-19 02:29 PM
self :face_with_tears_of_joy:
Still needs some changes, but it done the minimum.