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.jupiter.api.Test;
27  
28  import static org.junit.jupiter.api.Assertions.assertTrue;
29  
30  /**
31   * Test for class {@link FieldDerivativeStructure} on {@link Dfp}.
32   */
33  class FieldDerivativeStructureDfpTest extends FieldDerivativeStructureAbstractTest<Dfp> {
34  
35      private static final DfpField FIELD = new DfpField(25);
36  
37      @Override
38      protected Field<Dfp> getField() {
39          return FIELD;
40      }
41  
42      @Override
43      @Test
44      public void testComposeField() {
45          doTestComposeField(new double[] { 5.0e-24, 5.0e-24, 7.0e-24, 2.0e-23, 3.0e-23, 1.0e-100 });
46      }
47  
48      @Override
49      @Test
50      public void testComposePrimitive() {
51          doTestComposePrimitive(new double[] { 2.0e-14, 3.0e-14, 8.0e-14, 2.0e-13, 9.0e-14, 1.0e-100 });
52      }
53  
54      @Override
55      @Test
56      public void testHypotNoOverflow() {
57          doTestHypotNoOverflow(65600);
58      }
59  
60      @Override
61      @Test
62      public void testLinearCombinationReference() {
63          doTestLinearCombinationReference(x -> build(x), 4.15e-9, 4.21e-9);
64      }
65  
66      @Override
67      @Test
68      public void testLinearCombination1DSDS() {
69          doTestLinearCombination1DSDS(9.0e-9);
70      }
71  
72      @Override
73      @Test
74      public void testLinearCombination1FieldDS() {
75          doTestLinearCombination1FieldDS(9.0e-9);
76      }
77  
78      @Override
79      @Test
80      public void testLinearCombination1DoubleDS() {
81          doTestLinearCombination1DoubleDS(4.0e-8);
82      }
83  
84      @Override
85      @Test
86      public void testUlp() {
87          final RandomGenerator random = new Well19937a(0x36d4f8862421e0e4l);
88          for (int i = -300; i < 300; ++i) {
89              final double x = FastMath.scalb(2.0 * random.nextDouble() - 1.0, i);
90              assertTrue(FastMath.ulp(x) >= build(x).ulp().getReal());
91          }
92      }
93  
94  }