J.Pietschmann wrote:
Mark R. Diggory wrote:
(1) It is very important to also use ((double)x)*x instead of
(double)(x*x), as the loss of precision starts to occur at far
greater values than overflow occurs if one were doing integer arithmetic
IIRC Java shares also the C behaviour in that n*n b
J.Pietschmann wrote:
Mark R. Diggory wrote:
J.Pietschmann wrote:
No. If you cast the base into a double there is not much risk of
overflow: double x = n; y=x*x; or y=((double)n)*((double)n);
or even y=n*(double)n; (but avoid y=(double)n*n).
Double mantissa has IIRC 52 bits, this should be good
Mark R. Diggory wrote:
(1) It is very important to also use ((double)x)*x instead of
(double)(x*x), as the loss of precision starts to occur at far greater
values than overflow occurs if one were doing integer arithmetic
IIRC Java shares also the C behaviour in that n*n becomes
negative instead o
Mark R. Diggory wrote:
J.Pietschmann wrote:
No. If you cast the base into a double there is not much risk of
overflow: double x = n; y=x*x; or y=((double)n)*((double)n);
or even y=n*(double)n; (but avoid y=(double)n*n).
Double mantissa has IIRC 52 bits, this should be good for integers
up to 2^26
Phil Steitz wrote:
I am also a little confused by J's analysis. Do we know definitively that using
J2SE, there is precision loss in Math.pow(x,n) vs x*x*...*x (n terms) for small
integer n?
Actually no. I didn't know they use a specific library routine
which is stunningly good. Some tests showed d*
Phil Steitz wrote:
--- Brent Worden <[EMAIL PROTECTED]> wrote:
I am also a little confused by J's analysis. Do we know
definitively that using
J2SE, there is precision loss in Math.pow(x,n) vs x*x*...*x (n
terms) for small
integer n? If the answer is yes, we should establish the
guideline that
--- Brent Worden <[EMAIL PROTECTED]> wrote:
> >
> > I am also a little confused by J's analysis. Do we know
> > definitively that using
> > J2SE, there is precision loss in Math.pow(x,n) vs x*x*...*x (n
> > terms) for small
> > integer n? If the answer is yes, we should establish the
> > guidelin
--- "Mark R. Diggory" <[EMAIL PROTECTED]> wrote:
> Thanks for entertaining my sometimes naive questioning,
>
> J.Pietschmann wrote:
>
> > Mark R. Diggory wrote:
> >
> >> (1) Does it seem logical that when working with "n" (or
> >> values.length) to use Math.pow(n, x), as positive integers, the