Re: how to use recursive algorithm to determine all of the arrangements?
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Tue, 09 May 2006 14:48:00 GMT
<opalpa@xxxxxxxxx> wrote in message news:1147153506.499376.122360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
btw, How do I check for overflow on multiplication in Java (or any
other arithmetic operation)?
The simplest way is to check for integer overflow is to do the multiplication in floating point precision, and check if the result is larger than what would fit in whatever primitive type you're trying to store the value in.
e.g.
<pseudocode>
int a, b, result;
double temp = (double)a * (double)b;
if (temp > max_int_value) {
handleOverFlow();
} else {
result = (int)temp;
}
</pseudocode>
In the case of int, you could use long instead of double.
- Oliver
.
- Follow-Ups:
- Re: how to use recursive algorithm to determine all of the arrangements?
- From: Patricia Shanahan
- Re: how to use recursive algorithm to determine all of the arrangements?
- References:
- how to use recursive algorithm to determine all of the arrangements?
- From: index
- Re: how to use recursive algorithm to determine all of the arrangements?
- From: opalpa@xxxxxxxxx opalinski from opalpaweb
- how to use recursive algorithm to determine all of the arrangements?
- Prev by Date: Re: javac throwing native exception
- Next by Date: Profiling memory usage in tomcat 5
- Previous by thread: Re: how to use recursive algorithm to determine all of the arrangements?
- Next by thread: Re: how to use recursive algorithm to determine all of the arrangements?
- Index(es):
Relevant Pages
|
|