473,465 Members | 1,931 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why am I getting floating point exception?

Im just learning C an do not understand why the following code fails.
The while loop apperas to work fine until it bombs out with a
floating point exception. Whats going on?

Thanks
/*
* chapter 5, program 7
* Calculate GCD of two numbers.
*/

#include <stdio.h>

main ()
{
int u,v, temp;

temp = -1; // *** DEBUG
printf("Please type two non-negative integers.\n");

scanf("%d%d", &u,&v);

printf("\n\nThe GCD of %d and %d is ", u,v);

while ( u != 0)
{
printf ("\nu v temp ---> %d\t%d\t%d",u, v, temp); // *** DEBUG
temp = u % v;
u = v;
v = temp;
}

// printf("%d\n", u);

}
**** OUTPUT:

[sj@KUTI pic]$ a.out
Please type two non-negative integers.
150 35
The GCD of 150 and 35 is
u v temp ---> 150 35 -1
u v temp ---> 35 10 10
u v temp ---> 10 5 5
Floating point exception


Nov 15 '05 #1
2 26231
Steven Jones wrote:
while ( u != 0)
while (v != 0)
{
printf ("\nu v temp ---> %d\t%d\t%d",u, v, temp); // *** DEBUG
temp = u % v;
u = v;
v = temp;
}


--
pete
Nov 15 '05 #2
On 2005-10-30, Steven Jones <ca**@swbell.net> wrote:
Im just learning C an do not understand why the following code fails.
The while loop apperas to work fine until it bombs out with a
floating point exception. Whats going on?
Probable reasons for a floating point exception involving integers include:
Trap representations of signed types [unlikely on modern systems]
Overflow on signed types
Division by zero.
while ( u != 0)
{
printf ("\nu v temp ---> %d\t%d\t%d",u, v, temp); // *** DEBUG
temp = u % v; If 'v' reaches zero, you will have a division by zero here. u = v;
v = temp;
}

Nov 15 '05 #3

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

Similar topics

1
by: Andrew Straw | last post by:
I'm running into trouble when calling a 3rd party library (the Intel IPP library to do some fast math on a P4 processor). This is on debian linux 2.6.7 using python 2.3.4. I've been using Pyrex...
10
by: Vinny | last post by:
I have a few floating point questions/issues I wish to ask. An answer or discussion would be nice too :) Any links discussion the subject would be nice too.. 1. How do I generate an underflow...
687
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...
21
by: Allin Cottrell | last post by:
OK, I realize that what I am asking here is not likely to have a answer within the C standard. Nonetheless, it is not specific to any particular platform, so I'll hazard the question anyway. A...
13
by: Chris Stankevitz | last post by:
Hi, I have a very large Visual c++ .net 2003 7.1 native c application (approximately 500,000 lines of code). This application is a simulation that frequently works with floating point numbers....
4
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...
1
by: Shhnwz.a | last post by:
Hi, I have a problem regarding handling floating point error, specially Denormalisation error. I want to know is there any trick or technique to find bit length of the resultant before using and...
2
by: Martin Manns | last post by:
Hi, I am experiencing some trouble with gmpy v1.01. Multiplying an mpq with inf results in a floating point exception that exits python. Has this already been fixed in newer gmpy versions? ~...
39
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.