473,499 Members | 1,610 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 5760
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
3615
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....
5
3726
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...
687
22801
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...
24
2203
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...
7
3369
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...
15
3893
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...
13
4097
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...
4
2816
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...
32
4045
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 );...
39
3517
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...
0
7132
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
7009
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
7178
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
7390
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
4602
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...
0
3103
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
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
0
302
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.