[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RiminiLUG-General] java Exception



On Tue, Jan 19, 2010 at 03:41:19PM +0100, Simeone wrote:
> Non riesco ad intercettare l'errore "div by zero":
> 
> *float leftValue = getEvaluation();
>        divOpExp.prendiDestra().accept(this);
>        float rightValue = getEvaluation();
>        try {
>               value = leftValue/rightValue;  // possibile divisione
> per zero !!
>            }
>        catch (ArithmeticException exc){
>            System.out.println("---------Divisione per zero------------");
>            return false; }
>        return true;*
> 
> nel risultato in* value* mette Infinity, il quale a sua volta non
> riesco neanche a confrontarlo!
> Alla fine mi torna un true!

hai provato a cercare su google java division by zero?

http://java.sun.com/developer/TechTips/1998/tt0722.html

In the Java programming language, integral division by zero results in an
ArithmeticException. But for floating-point, no exception is thrown (in C++
the result of division by zero is undefined). The result of 1.0 / 0.0 is
positive infinity, indicated by the constant Double.POSITIVE_INFINITY (which,
in fact, is defined by performing this division).

This example illustrates an important point, which is that Java language
floating-point arithmetic operates according to a well-defined standard, known
as IEEE 754.

filippo
-- 
Filippo Giunchedi - http://esaurito.net - 0x6B79D401

I never forget a face, but in your case I'll be glad to make an exception.
-- Groucho Marx