473,666 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Floating point computations differ in different runs of same program

Hi,

I have a C program which does lots of computations in floats and
doubles,
It is processing the same file (same data) but in different runs of
the program (on the same machine) the results vary sometimes by
numeric value 1 (which is after rounding the resulting float number)
Is this expected behavior with floats and doulbe (with lots of
intermediate conversion in between) ?

Since There is only one thread so I guess the result should be same
always.

Any reason/pointers for the above mentioned behavior.

Thanks in advance
Rahul
Feb 14 '08 #1
3 1237
On Thu, 14 Feb 2008 01:17:12 -0800, Rahul wrote:
Hi,

I have a C program
Um... so why are you posting to a C++ newsgroup?
which does lots of computations in floats and doubles,
It is processing the same file (same data) but in different runs of the
program (on the same machine) the results vary sometimes by numeric
value 1 (which is after rounding the resulting float number) Is this
expected behavior with floats and doulbe (with lots of intermediate
conversion in between) ?

Since There is only one thread so I guess the result should be same
always.

Any reason/pointers for the above mentioned behavior.
Sure there's no (pseudo)-random number generation going on?

You'll probably have to post some (minimal) code that demonstrates the
problem to sort this out... but comp.lang.c might be a better bet.

--
Lionel B
Feb 14 '08 #2
"Rahul" <ra*********@lu cent.comwrote in message news:12******** *************** ***********@s19 g2000prg.google groups.com...
Hi,

I have a C program which does lots of computations in floats and
doubles,
It is processing the same file (same data) but in different runs of
the program (on the same machine) the results vary sometimes by
numeric value 1 (which is after rounding the resulting float number)
Is this expected behavior with floats and doulbe (with lots of
intermediate conversion in between) ?

Since There is only one thread so I guess the result should be same
always.

Any reason/pointers for the above mentioned behavior.
Possible causes are:
+ Use of uninitialized variables.
+ Use of a random generator.
+ Use of the changing environment, e.g. the current time.
+ ...
Feb 14 '08 #3
On Thu, 14 Feb 2008 16:59:27 +0100, "Fred Zwarts" <F.******@KVI.n lwrote:
>"Rahul" <ra*********@lu cent.comwrote in message news:12******** *************** ***********@s19 g2000prg.google groups.com...
>Hi,

I have a C program which does lots of computations in floats and
doubles,
It is processing the same file (same data) but in different runs of
the program (on the same machine) the results vary sometimes by
numeric value 1 (which is after rounding the resulting float number)
Is this expected behavior with floats and doulbe (with lots of
intermediate conversion in between) ?

Since There is only one thread so I guess the result should be same
always.

Any reason/pointers for the above mentioned behavior.

Possible causes are:
+ Use of uninitialized variables.
+ Use of a random generator.
+ Use of the changing environment, e.g. the current time.
+ ...
Maybe a vortex in the space-time continuum. It happens to my programs all the time. ;-)
Possibly explains what happens to my socks in the dryer, too.
Feb 26 '08 #4

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

Similar topics

31
3653
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms. However, they generate slightly different results for floating point numbers. Are they really supposed to generate exactly the same results? I guess so because both platforms are supposed to be IEEE floating point standard (754?) compliant. ...
5
3734
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are using the Debug-Version of the program, but it fails (or leads to false results) if we are using the Release-Version. After a long debugging session we found out, that our program was working correctly, but the floating point processing...
687
23350
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is basically the same. in C there arent the simplest things present like constants, each struct and enum...
15
3923
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this the EPSILON? I know in float.h a FLT_EPSILON is defined to be 10^-5. Does this mean that the computer cannot distinguish between 2 numbers that differ by less than this epsilon?
9
2227
by: Klaus Bonadt | last post by:
I have found strange behaviour in casting floating point values in C++ 6.0 to int: If I enter in the watch window while debugging in version 6.0 the following term: (1.4 - 1.0) * 10.0 the result will be 4.0 - as expected. But if I cast the same to int: (int)((1.4 - 1.0) * 10.0)
13
4125
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make sense to punch out from managed code to native code (I was using IJW) in order to do some amount of floating point work and, if so, what that certain amount of floating point work was approximately. To attempt to do this I made a program that...
39
3552
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody out there understands what happens. Essentially, when I subtract the (double) function value GRID_POINT(2) from a variable which has been assigned the same value before this gives a non-zero result and I really do not understand why.
15
7528
by: arnuld | last post by:
Next month I will start to work on a C++ based Software named CAT++ which is going to provide FORTRAN like arrays in C++ and will be used within Scientific Community and hence will heavily depend on Numerical-Computations. I was reading 29.16 ans 29.17 sections of FAQs: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.16 as a test, I just tried this program on Linux, GCC 4.2.2 and it gave me 2 different results:
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
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,...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7378
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...
0
5661
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
4192
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...
1
2765
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
1763
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.