Strange fprintf output

D

danep2

Hello all

This is a really strange problem. I have code that performs a few
calculations based on input from a joystick, and writes these values
to a file using basically the following code:

fprintf(fpResults, "i: %4.2f, j: %4.2f", i, j );

This works correctly (literally) 99.9999% of the time. However, once
every million or so writes I get the following output:

i: -1.#J, j: 1.#R

Does anybody know what this means?
 
A

Alexander Dong Back Kim

Hello all

This is a really strange problem.  I have code that performs a few
calculations based on input from a joystick, and writes these values
to a file using basically the following code:

fprintf(fpResults, "i: %4.2f, j: %4.2f", i, j );

This works correctly (literally) 99.9999% of the time. However, once
every million or so writes I get the following output:

i: -1.#J, j: 1.#R

Does anybody know what this means?

That's really interesting output. I've also never seen this before.
What compiler and working environment are you using?

cheers,
 
J

James Kanze

This is a really strange problem. I have code that performs a few
calculations based on input from a joystick, and writes these values
to a file using basically the following code:
fprintf(fpResults, "i: %4.2f, j: %4.2f", i, j );
This works correctly (literally) 99.9999% of the time. However, once
every million or so writes I get the following output:
i: -1.#J, j: 1.#R
Does anybody know what this means?

Perhaps your compiler vendor? This can't happen in a conforming
implementation unless your code has undefined behavior. Perhaps
the vendor could indicate what sort of undefined behavior might
cause it. (It will probably depend on how floating point values
are represented.)
 
D

danep2

Perhaps your compiler vendor?  This can't happen in a conforming
implementation unless your code has undefined behavior.  Perhaps
the vendor could indicate what sort of undefined behavior might
cause it.  (It will probably depend on how floating point values
are represented.)

--
James Kanze (GABI Software)             email:[email protected]
Conseils en informatique orientée objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

I am developing using Microsoft Visual Studio 2005. Prior to
migrating to VS 2005, we also experienced this problem with VC++ 6.0.
For what it's worth, this *usually* happen when the values of i or j
are very close to zero. (I don't know for a fact what they are, I am
simply inferring from the data immediately surrounding this output.)
Also, usually both variables are affected - i.e., if the output for i
is corrupt, the output for j will also be corrupt. However, other
floats being written in the same statement are never corrupted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top