View Javadoc
1   /*
2    * Licensed to the Hipparchus project under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The Hipparchus project licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.hipparchus.analysis.differentiation;
19  
20  import org.hipparchus.Field;
21  import org.hipparchus.dfp.Dfp;
22  import org.hipparchus.dfp.DfpField;
23  import org.hipparchus.random.RandomGenerator;
24  import org.hipparchus.random.Well19937a;
25  import org.hipparchus.util.FastMath;
26  import org.junit.Assert;
27  import org.junit.Test;
28  
29  /**
30   * Test for class {@link FieldDerivativeStructure} on {@link Dfp}.
31   */
32  public class FieldDerivativeStructureDfpTest extends FieldDerivativeStructureAbstractTest<Dfp> {
33  
34      private static final DfpField FIELD = new DfpField(25);
35  
36      @Override
37      protected Field<Dfp> getField() {
38          return FIELD;
39      }
40  
41      @Override
42      @Test
43      public void testComposeField() {
44          doTestComposeField(new double[] { 5.0e-24, 5.0e-24, 7.0e-24, 2.0e-23, 3.0e-23, 1.0e-100 });
45      }
46  
47      @Override
48      @Test
49      public void testComposePrimitive() {
50          doTestComposePrimitive(new double[] { 2.0e-14, 3.0e-14, 8.0e-14, 2.0e-13, 9.0e-14, 1.0e-100 });
51      }
52  
53      @Override
54      @Test
55      public void testHypotNoOverflow() {
56          doTestHypotNoOverflow(65600);
57      }
58  
59      @Override
60      @Test
61      public void testLinearCombinationReference() {
62          doTestLinearCombinationReference(x -> build(x), 4.15e-9, 4.21e-9);
63      }
64  
65      @Override
66      @Test
67      public void testLinearCombination1DSDS() {
68          doTestLinearCombination1DSDS(9.0e-9);
69      }
70  
71      @Override
72      @Test
73      public void testLinearCombination1FieldDS() {
74          doTestLinearCombination1FieldDS(9.0e-9);
75      }
76  
77      @Override
78      @Test
79      public void testLinearCombination1DoubleDS() {
80          doTestLinearCombination1DoubleDS(4.0e-8);
81      }
82  
83      @Override
84      @Test
85      public void testUlp() {
86          final RandomGenerator random = new Well19937a(0x36d4f8862421e0e4l);
87          for (int i = -300; i < 300; ++i) {
88              final double x = FastMath.scalb(2.0 * random.nextDouble() - 1.0, i);
89              Assert.assertTrue(FastMath.ulp(x) >= build(x).ulp().getReal());
90          }
91      }
92  
93  }