473,504 Members | 13,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Operations between float

1 New Member
Hello,

I have a problem regarding to float's operations. I have the following loop:
Expand|Select|Wrap|Line Numbers
  1. ////////////////////////////////////////////////////
  2. x=(float)0.0;
  3. for (i=0; i<262144; i++)
  4. {
  5. x=x+(1.0*3.814697265);
  6. }
  7. ////////////////////////////////////////////////////
  8.  
The final value of x must be 1,000,000 but it isn't. Does anyone know why??
thanks
Nov 30 '07 #1
2 1469
sicarie
4,677 Recognized Expert Moderator Specialist
Yeah. Run this:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.    float x=0.0;
  7.    int i_limit = 0;
  8.    for (int i=0; i<262144; i++)
  9.    {
  10.       x=x+(1.0*3.814697265);
  11.       if (i_limit < 5)
  12.       {
  13.          cout << x << << endl;
  14.       }
  15.       i_limit++;
  16.    }
  17.  
  18.    return 0;
  19. }
And then do the first five calculations by hand. Do you see anything interesting?
Nov 30 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
And keep in mind that a float has only 6 significant figures.
Nov 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2249
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
7
1639
by: David | last post by:
How can I do a bit-wise operation on a UInt, such as: dim x as UInt32 x = x And &H80 It says the "And operator isn't defined for UInt32" But why not? And is there a work-around?
20
3117
by: ehabaziz2001 | last post by:
That program does not yield and respond correctly espcially for the pointers (*f),(*i) in print_divide_meter_into(&meter,&yds,&ft,&ins); /*--------------pnt02own.c------------ ---1 inch = 2.51...
6
8393
by: jawilson2 | last post by:
Hello, I have some data that stores two 16-bit integers in a 32-bit float, and I would like to extract the data. I want to do something like ...
9
2399
by: junaidnaseer | last post by:
ok I know I posted this question previously and then I got a reply and I realized that I had asked a really dumb question but now I realize that my question wasn't that dumb at all ! I had asked...
4
3332
by: Ney André de Mello Zunino | last post by:
Hello. The following program: #include <list> #include <iterator> #include <algorithm> #include <cmath> #include <iostream>
4
2115
by: alex | last post by:
hi friends ... i am facing a problem while detecting floating point operations in my project, please help me. i want to find out the places in my C/C++ project where i am doing floating...
4
6205
by: siryuhan | last post by:
I am trying to apply bitwise operations on float, double, and long double values. I do not believe this is possible natively, so I created a wrapper class to construct a double value given two...
0
865
by: Terry Reedy | last post by:
aditya shukla wrote: .... Either because your text file starts with a blank line or because ..readline does not work when you open in binary mode. In any case, you should probably change 'rb'...
0
7213
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,...
0
7098
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...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
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...
0
7471
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...
0
3187
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...
0
1526
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 ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
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...

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.