473,566 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

floating point execption

4 New Member
for some reason in my program when i try and add a number to my current number i get a floating point exception now i have narrowed down were it stops working to line 398 but i dont know as to why it is stopping right there. Here is my code any help would be great.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. #undef NULL //un defines anything from a class that has the same name as one of your constants
  7.  
  8. typedef int element;
  9.  
  10. const int NULL = 0;
  11. const char sentinel = '#';
  12.  
  13. class listnode{
  14.  
  15.     public:
  16.  
  17.         element data;
  18.  
  19.         listnode* next;
  20.  
  21.     };
  22.  
  23.  
  24. class Llist{
  25.  
  26.     private:
  27.  
  28.         listnode* head;
  29.  
  30.         listnode* tail;
  31.         char vignum;
  32.  
  33.     public:
  34.  
  35.         void read();
  36.  
  37.         void print();
  38.         void clean();
  39.         void ReadBackward();
  40.         char read_element();
  41.         void Inserthead(element);
  42.         void inserttail(char);
  43.         element DeleteHead();
  44.         void steal(Llist&);
  45.         void append(Llist&);
  46.         void duplicate(Llist&);
  47.         void reverse();
  48.         void Mergeordered(Llist&, Llist&);
  49.         void Printinreverse();
  50.         void Mainmenu();
  51.         void Helpmenu();
  52.         void addvigesimalnum();
  53.         void newvigesimalnum();
  54.         void multiplyvigesimalnum();
  55.         int digitconvertor(char);
  56.         char convertback(int);
  57.         void Multiadd(int);
  58.         void difadd(Llist & second, Llist & combo, Llist & copy);
  59.  
  60.         Llist();
  61.         ~Llist();
  62.  
  63.  
  64.  
  65.  
  66.  
  67.     };
  68.  
  69. void Llist::difadd(Llist & second, Llist & combo, Llist & copy){
  70.     char cnum1;
  71.     char cnum2;
  72.     char cnumber;
  73.     element num1;
  74.     element num2;
  75.     element number;
  76.     element remainder;
  77.     listnode * temp1;
  78.  
  79.     listnode * temp2;
  80.  
  81.     temp1 = copy.head;
  82.  
  83.     temp2 = second.head;
  84.  
  85.     combo.head = NULL;
  86.  
  87.  
  88.     while((temp1 != NULL)&&(temp2 != NULL)){
  89.         cnum1 = temp1 -> data;
  90.         cnum2 = temp2 -> data;
  91.  
  92.         cnum1 = DeleteHead();
  93.         cnum2 = second.DeleteHead();
  94.  
  95.         num1 = digitconvertor(cnum1);
  96.         num2 = digitconvertor(cnum2);
  97.  
  98.         number = (num1 % num2) + remainder;    // Line 398
  99.         remainder = (num1 + num2) / 20;
  100.  
  101.         cnumber = convertback(number);
  102.  
  103.         combo.inserttail(cnumber);
  104.  
  105.         temp1 = temp1 -> next;
  106.         temp2 = temp2 -> next;    
  107.  
  108.         cout << "here 1" << endl;
  109.         combo.print();
  110.     }
  111. }
  112.  
Apr 8 '10 #1
4 5761
whodgson
542 Contributor
L 398 says that 'number' is to be assigned the value of the remainder of num1 % num2 + remainder; but i cant see where the second remainder comes from.
Apr 9 '10 #2
Banfa
9,065 Recognized Expert Moderator Expert
The first time through the loop the variable remainder is not initialised to any value and is used on line 398 before it is set on line 399.

Using an uninitialise automatic variable is undefined behaviour.
Apr 9 '10 #3
donbock
2,426 Recognized Expert Top Contributor
Line 398 evaluates num1 % num2.
Are you sure num2 isn't zero?
Apr 9 '10 #4
donbock
2,426 Recognized Expert Top Contributor
Line 398 evaluates num1 % num2.
Are you sure num2 isn't zero?

Wait a minute! All the variables on line 398 are integers. I don't see any floating point operations, so I don't know why you're getting a floating point exception.
Apr 9 '10 #5

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

Similar topics

31
3632
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...
5
3729
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...
687
23043
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...
24
2215
by: j0mbolar | last post by:
C supports single precision floating point and double precision floating point but does it support fixed floating point? i've read that fixed floating point is more accurate than single precision floating point when dealing with dollars and cents.
7
3380
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would discuss about ways to emulate floating point calculations with just long int or long long int. For eg., if i've a formula X=(1-b)*Y + b*Z in floating...
15
3906
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...
13
4108
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...
4
2825
by: jacob navia | last post by:
Hi people I continue to work in the tutorial for lcc-win32, and started to try to explain the floating point flags. Here is the relevant part of the tutorial. Since it is a difficult part, I would like your expert advise before I publish any serious nonsense. Any comments are welcome, style, organization, hard errors, etc.
32
4065
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon ); } int main() { std::deque<double> pt ;
39
3530
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...
0
7584
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...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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...
1
7644
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...
0
6260
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...
0
3643
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...
1
2083
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
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
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...

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.