Skip to main content

Java (67 chars)

float r(){float p=0,s=4,i=1E6f;while(--i>0)p+=(s=-s)/i--;return p;}
float r(){float p=0,s=4,i=1E6f;while(--i>0)p+=(s=-s)/i--;return p;}

Note that this avoids loss of significance by adding the numbers up in the correct order.

Java (67 chars)

float r(){float p=0,s=4,i=1E6f;while(--i>0)p+=(s=-s)/i--;return p;}

Note that this avoids loss of significance by adding the numbers up in the correct order.

Java (67 chars)

float r(){float p=0,s=4,i=1E6f;while(--i>0)p+=(s=-s)/i--;return p;}

Note that this avoids loss of significance by adding the numbers up in the correct order.

Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169

Java (67 chars)

float r(){float p=0,s=4,i=1E6f;while(--i>0)p+=(s=-s)/i--;return p;}

Note that this avoids loss of significance by adding the numbers up in the correct order.