# not getting precision as expected

• 01-29-2012, 02:11 AM
ellipse
not getting precision as expected
Per Ellipse Cirumference-High Accuracy from Polynomial

<script LANGUAGE="JavaScript">
function ec(form) {
X1=eval(form.A.value)
X2=eval(form.B.value)
HT1 = X2-X1;
HB1 = X2+X1;
H1 = (Math.pow(HT1,2))/(Math.pow(HB1,2));
H2 = 4-3*H1;
C1 = Math.PI*HB1*(1+(3*H1)/(10+Math.pow(H2,0.5))+(5.1227200788995887836041683 376024e-4)*Math.pow(H1,(0.3629877*Math.pow(H1,1024)-0.80311737+Math.pow(H1,512)+1.7512218474*Math.pow( H1,256)-1.734067037*Math.pow(H1,128)+2.957992923*Math.pow( H1,64)-1.545484804*Math.pow(H1,32)+2.7559284083*Math.pow( H1,16)+0.176369301*Math.pow(H1,8)+2.95202242*Math. pow(H1,4)-0.600612825*Math.pow(H1,2)+4.2106880013*H1+5.89029 54352)));
P = 9;
C1 = C1.toPrecision(P);
form.C.value = C1}
</SCRIPT>
<form>

When inputting numbers X1=1, X2=0.5 I am getting 4.84422412 when it should be 4.84422411. I did the calculations on a spreadsheet and verified 4.84422411 should be the correct answer. I changed the value of (44-14*pi)/(11*pi) to the 5.122...e-4 and even added more decimal places to the coefficients (that the truncated coefficients as listed on my web page were derived from) and still it does not help (this should not matter anyway but thought I would try).

I tried putting double declarations above and then deleted them when I was getting no response (perhaps I don't know how to properly do it).

Would someone copy the above into a program to troubleshoot the above and if somehow adding the double precision syntax or some other fashion to fix this, please show me how I should include into my program above.

Thanks!
• 01-29-2012, 02:12 AM
Fubarable
Re: not getting precision as expected
What does this have to do with coding in the Java programming language?
• 01-29-2012, 02:13 AM
ellipse
Re: not getting precision as expected
Note, there are no gaps in the numbers even though it is showing in the above window as such.
• 01-29-2012, 02:14 AM
ellipse
Re: not getting precision as expected
Hmm, perhaps this part: "<script LANGUAGE="JavaScript">"
• 01-29-2012, 02:14 AM
Fubarable
Re: not getting precision as expected
Quote:

Originally Posted by ellipse
Note, there are no gaps in the numbers even though it is showing in the above window as such.

Again, what does this have to do with coding in Java? Your post looks like nothing but Javascript, and surely you're smart enough to know the difference before posting here, right?