Re: weird problem
- From: jt@xxxxxxxxxxx (Jens Thoms Toerring)
- Date: 24 Jan 2007 23:52:40 GMT
Alef.Veld@xxxxxxxxx wrote:
On Jan 24, 10:55 pm, j...@xxxxxxxxxxx (Jens Thoms Toerring) wrote:
So I am lead to assume that '(grid_size - grid_start)' is the size of
a square grid and you want to compare the number of points on that
grid to the number of 'collisions'. In that case you need to round
the result of squaring the grid size to the nearest int,
You're right. This might actually be my problem then. Would a cast
suffice or do i have to manually round this off somehow with a
conversion specifier.
A conversion specifier only can be used in printf() etc. And a cast
alone won't do since it simply cuts off everything after the decimal
point. But that won't get you 144 from 143.99999999. You need to
round to the nearest integer, e.g. by using
( int ) ( d < 0.0 ? ceil( d - 0.5 ) : floor( d + 0.5 ) );
where d is your float or double - or, since you are rounding
the square of a float, which is always positive,
( int ) floor( d + 0.5 )
will do.
BTW, you also have an off-by-one (fence-post) error: if the size
of the grid is (a - b) then the number of points on th grid is
(a - b + 1) * (a - b + 1).
Ah. I see that without proper code this is getting confusing for the
both of us :-). I will see if i can supply both 2 functions which cause
my troubles.
Yes, please do that;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@xxxxxxxxxxx
\__________________________ http://toerring.de
.
- Follow-Ups:
- Re: weird problem
- From: Alef . Veld
- Re: weird problem
- References:
- weird problem
- From: atv
- Re: weird problem
- From: Jens Thoms Toerring
- Re: weird problem
- From: Alef . Veld
- Re: weird problem
- From: Jens Thoms Toerring
- Re: weird problem
- From: Alef . Veld
- weird problem
- Prev by Date: Re: Decimal to Roman Numerals
- Next by Date: Re: Basic questions about C
- Previous by thread: Re: weird problem
- Next by thread: Re: weird problem
- Index(es):
Relevant Pages
|