Re: how to use recursive algorithm to determine all of the arrangements?



<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

.



Relevant Pages

  • Re: C floating point
    ... > C supports single precision floating point and double precision ... > that fixed floating point is more accurate than single precision ... int dollar; ...
    (comp.lang.c)
  • Re: gcc strangeness
    ... binary floating point arithmetic, rather than gcc. ... The correct solution is to use rint(3), ... Switching to double precision will help but is still not a complete ...
    (freebsd-hackers)
  • Re: double is integer?
    ... safe thing to do ... floating point computations, you may have a value close to but not ... precision anyway. ... long int i = d; ...
    (microsoft.public.vc.mfc)
  • Re: Problem in Float Arithmetic
    ... precision of an integer of the same number of bits of significance as the mantissa of the ... The problem, for example, is that 'float' has fewer bits than ... 'int', so it only becomes interesting when you start using 'double'. ... Floating point arithmetic on integer values that produces integer values is ...
    (microsoft.public.vc.mfc)
  • [PATCH][PPC64] Handle altivec assist exception properly
    ... This is the PPC64 counterpart of the PPC32 Altivec assist exception ... Fortunately there are only a limited set of altivec instructions ... +static unsigned int eexp2 ... +/* Round to floating integer, ...
    (Linux-Kernel)