473,657 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange fprintf output

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(fpResul ts, "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?
Jun 27 '08 #1
2 1582
On Apr 20, 10:11 pm, danep2 <danepow...@gma il.comwrote:
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(fpResul ts, "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.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #2
On Apr 21, 4:18*am, James Kanze <james.ka...@gm ail.comwrote:
On Apr 20, 10:11 pm, danep2 <danepow...@gma il.comwrote:
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(fpResul ts, "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.)

--
James Kanze (GABI Software) * * * * * * email:james.ka. ..@gmail.com
Conseils en informatique orientée objet/
* * * * * * * * * *Beratung in objektorientier ter Datenverarbeitu ng
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.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1589
by: Noah Roberts | last post by:
There is some windows specific code in this, but I believe the issue to be something standard so... The problem is that after attaching the name of the subdirectory I have something like "d:\db\db-4.1.25\", which has 16 characters; but when it arrives in the next call it looks more like "d:\db\db-4.1.25\(clubs)", which has 17 characters. What is even more interesting is that the test "if (dir != '\\')" fails when there is a clubs at the...
6
2107
by: Rick | last post by:
Hi, Sorry, I couldn't find a better title for this post. Anyway, I got a piece of C code which only works well if I put a fprintf in it. Here's the code : unsigned int8 Port_getPortNum( char *port ) { fprintf(DB9, "port = %s\r\n", port ); // Don't know why but I need this fprintf?! if ( port == 'A' )
11
1664
by: Marlene Stebbins | last post by:
Something very strange is going on here. I don't know if it's a C problem or an implementation problem. The program reads data from a file and loads it into two arrays. When xy, x, y, *xlist and *ylist are ints or floats there is no apparent problem. If these variables are doubles, the program crashes. Furthermore, the crashes occur only when xlist and ylist are free()ed. When the above variables are doubles and the calls to free() are...
6
2992
by: Magix | last post by:
Hi, I want to use fprintf to write to a file. My question about the formatted output How can I format so that I can allocate certain width for each %s (Left-aignlied) ? Example: fprintf("%s %s %s %s, name, age, city, status); <-------------------><----------------><----------------><------------->
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.