commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: [Math] Factorial
Date Tue, 02 Nov 2010 21:06:01 GMT
exp(1000) is also not equal to infinity, but that is what the JVM returns.

On Tue, Nov 2, 2010 at 10:16 AM, Gilles Sadowski <
gilles@harfang.homelinux.org> wrote:

> > > In "MathUtils", the documentation of method "factorialDouble" says that
> it
> > > will return INFINITY when the result is larger than MAX_VALUE. It also
> says
> > > that this will happen when n > 170.  So, I think that it should be more
> > > appropriate to throw an "ArithmeticException" (as is done in the method
> > > "factorial" when n > 20).
> > >
> > Interesting question.  The rationale for the current setup is that there
> is no infinity for Integers (nor NaN) so exception is the only option;
> whereas  infinity is an option for doubles and while we can argue about the
> absence of overflow exceptions in Java, returning Infinity on double
> overflow is consistent with the Java language spec (4.2.3).
>
> 171! is not equal to Infinity, so the returned value is wrong. That's why I
> suggest to signal the problem by throwing the exception.
>
>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message