DfpMath { public static Dfp sin(final Dfp a) { final Dfp pi = a.getField().getPi(); final Dfp zero = a.getField().getZero(); boolean neg = false; Dfp x = a.remainder(pi.multiply(2)); if (x.lessThan(zero)) { x = x.negate(); neg = true; } if (x.greaterThan(pi.divide(2))) { x = pi.subtract(x); } Dfp y; if (x.lessThan(pi.divide(4))) { Dfp c[] = new Dfp[2]; c[0] = x; c[1] = zero; y = sinInternal(split(x)); } else { final Dfp c[] = new Dfp[2]; final Dfp[] piSplit = a.getField().getPiSplit(); c[0] = piSplit[0].divide(2).subtract(x); c[1] = piSplit[1].divide(2); y = cosInternal(c); } if (neg) { y = y.negate(); } return a.newInstance(y); } private  DfpMath(); static Dfp pow(Dfp base, int a); static Dfp exp(final Dfp a); static Dfp log(Dfp a); static Dfp pow(Dfp x, final Dfp y); static Dfp sin(final Dfp a); static Dfp cos(Dfp a); static Dfp tan(final Dfp a); static Dfp atan(final Dfp a); static Dfp asin(final Dfp a); static Dfp acos(Dfp a);  }
@Test public void testSin() { test(DfpMath.sin(pinf), nan, DfpField.FLAG_INVALID|DfpField.FLAG_INEXACT, "sin #1"); test(DfpMath.sin(nan), nan, DfpField.FLAG_INVALID|DfpField.FLAG_INEXACT, "sin #2"); test(DfpMath.sin(factory.getZero()), factory.getZero(), DfpField.FLAG_INEXACT, "sin #3"); test(DfpMath.sin(factory.getPi()), factory.getZero(), DfpField.FLAG_INEXACT, "sin #4"); test(DfpMath.sin(factory.getPi().negate()), factory.newDfp("-0"), DfpField.FLAG_INEXACT, "sin #5"); test(DfpMath.sin(factory.getPi().multiply(2)), factory.getZero(), DfpField.FLAG_INEXACT, "sin #6"); test(DfpMath.sin(factory.getPi().divide(2)), factory.getOne(), DfpField.FLAG_INEXACT, "sin #7"); test(DfpMath.sin(factory.getPi().divide(2).negate()), factory.getOne().negate(), DfpField.FLAG_INEXACT, "sin #8"); test(DfpMath.sin(DfpMath.atan(factory.getOne())), factory.newDfp("0.5").sqrt(), DfpField.FLAG_INEXACT, "sin #9"); test(DfpMath.sin(DfpMath.atan(factory.getOne())).negate(), factory.newDfp("0.5").sqrt().negate(), DfpField.FLAG_INEXACT, "sin #10"); test(DfpMath.sin(DfpMath.atan(factory.getOne())).negate(), factory.newDfp("0.5").sqrt().negate(), DfpField.FLAG_INEXACT, "sin #11"); test(DfpMath.sin(factory.newDfp("0.1")), factory.newDfp("0.0998334166468281523"), DfpField.FLAG_INEXACT, "sin #12"); test(DfpMath.sin(factory.newDfp("0.2")), factory.newDfp("0.19866933079506121546"), DfpField.FLAG_INEXACT, "sin #13"); test(DfpMath.sin(factory.newDfp("0.3")), factory.newDfp("0.2955202066613395751"), DfpField.FLAG_INEXACT, "sin #14"); test(DfpMath.sin(factory.newDfp("0.4")), factory.newDfp("0.38941834230865049166"), DfpField.FLAG_INEXACT, "sin #15"); test(DfpMath.sin(factory.newDfp("0.5")), factory.newDfp("0.47942553860420300026"), DfpField.FLAG_INEXACT, "sin #16"); test(DfpMath.sin(factory.newDfp("0.6")), factory.newDfp("0.56464247339503535721"), DfpField.FLAG_INEXACT, "sin #17"); test(DfpMath.sin(factory.newDfp("0.7")), factory.newDfp("0.64421768723769105367"), DfpField.FLAG_INEXACT, "sin #18"); test(DfpMath.sin(factory.newDfp("0.8")), factory.newDfp("0.71735609089952276163"), DfpField.FLAG_INEXACT, "sin #19"); test(DfpMath.sin(factory.newDfp("0.9")), factory.newDfp("0.78332690962748338847"), DfpField.FLAG_INEXACT, "sin #20"); test(DfpMath.sin(factory.newDfp("1.0")), factory.newDfp("0.84147098480789650666"), DfpField.FLAG_INEXACT, "sin #21"); test(DfpMath.sin(factory.newDfp("1.1")), factory.newDfp("0.89120736006143533995"), DfpField.FLAG_INEXACT, "sin #22"); test(DfpMath.sin(factory.newDfp("1.2")), factory.newDfp("0.93203908596722634968"), DfpField.FLAG_INEXACT, "sin #23"); test(DfpMath.sin(factory.newDfp("1.3")), factory.newDfp("0.9635581854171929647"), DfpField.FLAG_INEXACT, "sin #24"); test(DfpMath.sin(factory.newDfp("1.4")), factory.newDfp("0.98544972998846018066"), DfpField.FLAG_INEXACT, "sin #25"); test(DfpMath.sin(factory.newDfp("1.5")), factory.newDfp("0.99749498660405443096"), DfpField.FLAG_INEXACT, "sin #26"); test(DfpMath.sin(factory.newDfp("1.6")), factory.newDfp("0.99957360304150516323"), DfpField.FLAG_INEXACT, "sin #27"); }