Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread Mark R. Diggory
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

Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread Mark R. Diggory
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

Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread J.Pietschmann
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

Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread J.Pietschmann
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

Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread J.Pietschmann
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*

Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread Mark R. Diggory
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

RE: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-19 Thread Phil Steitz
--- 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

Re: [math] Math.pow usage was: Re: cvs commit: ...

2003-06-18 Thread Phil Steitz
--- "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