Path: chuka.playstation.co.uk!news From: Craig Graham Newsgroups: scee.yaroze.programming.gnu_compiler Subject: Re: printf works, code doesn't Date: Thu, 16 Apr 1998 11:42:58 +0100 Organization: Intelligent Research Lines: 28 Message-ID: <3535E0B1.3FDF2F4E@hinge.mistral.co.uk> References: <3532D4BA.49B30CA9@sinclair.net> <3534730B.2417@127.0.0.1> <35357014.E195CEDC@sinclair.net> NNTP-Posting-Host: 194.131.235.3 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; I) Joshua Meeds wrote: > Well, that was the actual code, but that line wasn't remmed out (I think > it was my newsgroup poster that messed it up). You know what fixed the > problem? I had to type cast the equation as a double, like so: > > Fun=(double)(((Y2-Y1) / (X2-X1)); The outer brackets mean that as all parameters are unsigned long int's,the result of the division is truncated to an integer before casting to a double - so you lose the fractional component. Also, as X1, etc, are unsigned, the result of Y2-Y1 will always be unsigned, so you'll lose any directional information from the calculation. Try: Fun=((double)(Y2-Y1))/((double)(X2-X1)); or alternatively, make X1, etc, into doubles instead of u_long's. Craig. >