Skip to main content

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}
float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. This also relies on undefined behaviour with respect to the order in which the ++ are executed; thanks to ugoren for pointing this out. I've tested with gcc 4.4.3 under 64-bit Linux .

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. This also relies on undefined behaviour with respect to the order in which the ++ are executed; thanks to ugoren for pointing this out. I've tested with gcc 4.4.3 under 64-bit Linux .

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. This also relies on undefined behaviour with respect to the order in which the ++ are executed; thanks to ugoren for pointing this out. I've tested with gcc 4.4.3 under 64-bit Linux .

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

added 31 characters in body
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. This also relies on undefined behaviour with respect to the order in which the (Note:++ are executed; thanks to ugoren for pointing this out. I've tested with gcc 4.4.3) under 64-bit Linux .

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. (Note: tested with gcc 4.4.3).

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. This also relies on undefined behaviour with respect to the order in which the ++ are executed; thanks to ugoren for pointing this out. I've tested with gcc 4.4.3 under 64-bit Linux .

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

added 31 characters in body
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. (Note: tested with gcc 4.4.3).

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion.

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

C (GCC) (44 chars)

float p(i){return i<1E6?4./++i-p(++i):0;}

That's 41 chars, but it also has to be compiled with -O2 to get the optimiser to eliminate the tail recursion. (Note: tested with gcc 4.4.3).

Note that unless the optimiser also reorders the sum, it will add from the smallest number, so it avoids loss of significance.

Call as p().

edited body
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169
Loading
Source Link
Peter Taylor
  • 43.1k
  • 4
  • 70
  • 169
Loading