[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Integer arithmetic in Java
From: |
Joshua O'Madadhain |
Subject: |
Re: Integer arithmetic in Java |
Date: |
Tue, 4 Dec 2001 15:27:39 -0800 (Pacific Standard Time) |
On Tue, 4 Dec 2001, M Lang / S Railsback wrote:
> In de-bugging our first model in Java Swarm we finally figured out that:
>
> aFloat = (anInt) / (anotherInt);
>
> gives aFloat a value truncated to a whole number. (We were doing
> movement calculations on a 2D grid with integer coordinates, trying to
> figure out why the critters ended up in the wrong places.)
>
> Pardon my inexperience, but is that something that everybody knows?
Well, given the fact that it tripped you, I'd hesitate to say that it's
something that "everyone knows", but it is a pretty standard feature of
most general-purpose programming languages that I've dealt with (C/C++,
Java, Pascal, ...). Generally speaking, division of integral types gets
truncated to an integer, although there is some disagreement among
languages over whether -123.4 gets truncated to -123 or to -124. You
could say that it's one of the classic computer arithmetic "gotchas".
Joshua O'Madadhain
address@hidden Per Obscurius...www.ics.uci.edu/~jmadden
Joshua Madden: Information Scientist, Musician, Philosopher-At-Tall
It's that moment of dawning comprehension that I live for--Bill Watterson
My opinions are too rational and insightful to be those of any organization.
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.