fork download
  1. import java.util.function.BiFunction;
  2.  
  3. class scratch {
  4.  
  5. void check(long m, double z, double expected, double epsilon) {
  6. double result = getFunction().apply(m, z);
  7. System.out.println
  8. ("Result of m = " + m + ", z = " + z + " is "+(Math.abs(result - expected) > epsilon ? "**not** ":"")+"within eps = " + epsilon + ", error=" + Math.abs(result - expected) + ".\nresult = " + result + "\nexpect = " + expected + "\n");
  9. }
  10.  
  11. BiFunction<Long, Double, Double> getFunction() {
  12. return (m,z)->{double p=1-m%2*2,f=0;long i=m;for(;i>0;)p*=i--;for(;i<1e7;)f-=p*Math.pow(z+i++,~m);return f;};
  13. }
  14.  
  15. public static void main(String[] args) {
  16. new scratch() {
  17. void v() {
  18. double epsilon = 1E-10;
  19. check(1, 1, 1.644934066848227, epsilon);
  20. check(2, 1, -2.404113806319188, epsilon);
  21. check(17, 2, 1357763223.715975761413574, epsilon);
  22. check(5, 40, 0.0000002493894351, epsilon);
  23. check(9, 53.59375, 0.00000000001201026493, epsilon);
  24. check(35, 9, 469354.958166260155849, epsilon);
  25. check(46, 5, -7745723758939047727202304.000000000000000, epsilon);
  26. check(7, 1.2222222222222222, 1021.084176496877490, epsilon);
  27. check(28, 6.25, -2567975.924144014250487, epsilon);
  28. check(2, 7.85, -0.018426049840992, epsilon);
  29. }
  30. }.v();
  31. }
  32. }
Success #stdin #stdout 4.88s 38592KB
stdin
Standard input is empty
stdout
Result of m = 1, z = 1.0 is **not** within eps = 1.0E-10, error=1.0000096750673038E-7.
result = 1.6449339668472596
expect = 1.644934066848227

Result of m = 2, z = 1.0 is within eps = 1.0E-10, error=1.8546053581758315E-11.
result = -2.404113806300642
expect = -2.404113806319188

Result of m = 17, z = 2.0 is **not** within eps = 1.0E-10, error=4.76837158203125E-7.
result = 1.3577632237159753E9
expect = 1.3577632237159758E9

Result of m = 5, z = 40.0 is within eps = 1.0E-10, error=8.512681119905718E-20.
result = 2.493894350999149E-7
expect = 2.493894351E-7

Result of m = 9, z = 53.59375 is within eps = 1.0E-10, error=1.40745750578178E-21.
result = 1.2010264931407457E-11
expect = 1.201026493E-11

Result of m = 35, z = 9.0 is within eps = 1.0E-10, error=0.0.
result = 469354.95816626016
expect = 469354.95816626016

Result of m = 46, z = 5.0 is within eps = 1.0E-10, error=0.0.
result = -7.745723758939048E24
expect = -7.745723758939048E24

Result of m = 7, z = 1.222222222222222 is within eps = 1.0E-10, error=1.0231815394945443E-12.
result = 1021.0841764968785
expect = 1021.0841764968775

Result of m = 28, z = 6.25 is **not** within eps = 1.0E-10, error=4.6566128730773926E-10.
result = -2567975.9241440147
expect = -2567975.9241440143

Result of m = 2, z = 7.85 is within eps = 1.0E-10, error=7.310436977991941E-13.
result = -0.018426049840260958
expect = -0.018426049840992