This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: sprintf misbehaving with floats
- From: Bob Dunlop <bob dot dunlop at xyzzy dot org dot uk>
- To: "Kline, Matthew" <matthew dot kline at flukenetworks dot com>
- Cc: "newlib at sourceware dot org" <newlib at sourceware dot org>
- Date: Fri, 3 Jul 2015 08:42:00 +0100
- Subject: Re: sprintf misbehaving with floats
- Authentication-results: sourceware.org; auth=none
- References: <E8C63C11EA3FB04DBDFEDECEFD927FD1267F079A at US-EVT-EXM04-P dot global dot tektronix dot net>
Hi,
On Thu, Jul 02 at 05:58, Kline, Matthew wrote:
...
> But the following
>
> sprintf(foo, "%f is a float", 8675.309f);
>
> produces garbage similar to
Don't use floats very often myself so this is just speculation.
What happens is you try:
sprintf(foo, "%f is a float", 8675.309);
sprintf %f is expecting a double and I don't know if the compiler
will promote an explicitly set float to a double when passed as a
parameter.
Next I'd be looking at the storage that foo is pointing at. Is it
somewhere that might be overwritten or reused ?
--
Bob Dunlop