-
June 4th, 2012, 04:52 PM
#1
Annoying problem
I have this code:
Code:
int x,y;
long a=0,b=0,dx=0,dy=0;
dx=x1-x0;
dy=y1-y0;
a=dy/dx;
b=y0-a*x0;
When dx is larger than dy In the last line 'a' is always. In debug it acts like a is an Int. I don't get it.
Why?
-
June 4th, 2012, 04:58 PM
#2
Re: Annoying problem
Originally Posted by spikeyz
I have this code:
Code:
int x,y;
long a=0,b=0,dx=0,dy=0;
dx=x1-x0;
dy=y1-y0;
a=dy/dx;
b=y0-a*x0;
When dx is larger than dy In the last line 'a' is always. In debug it acts like a is an Int. I don't get it.
Why?
The code has undeclared variables.
What is x1? x0? y1? y0?
Second, you divide an integer type by an integer type, you get an integer result. Integer/intergral types include int, short, long, char, and the unsigned varieties of those. If you want floating point, then use float or double types.
Regards,
Paul McKenzie
-
June 5th, 2012, 04:27 AM
#3
Re: Annoying problem
I would also check if dx is non-zero before performing such a division:
Originally Posted by spikeyz
Victor Nijegorodov
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|