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 package org.hipparchus.util;
18
19 import org.hipparchus.CalculusFieldElement;
20
21 /** Holder for both hyperbolic sine and hyperbolic cosine values.
22 * <p>
23 * This class is a simple container, it does not provide any computational method.
24 * </p>
25 * @see FastMath#sinhCosh(double)
26 * @param <T> the type of the field elements
27 * @since 2.0
28 */
29 public class FieldSinhCosh<T> {
30
31 /** Value of the hyperbolic sine. */
32 private final T sinh;
33
34 /** Value of the hyperbolic cosine. */
35 private final T cosh;
36
37 /** Simple constructor.
38 * @param sinh value of the hyperbolic sine
39 * @param cosh value of the hyperbolic cosine
40 */
41 public FieldSinhCosh(final T sinh, final T cosh) {
42 this.sinh = sinh;
43 this.cosh = cosh;
44 }
45
46 /** Get the value of the hyperbolic sine.
47 * @return value of the hyperbolic sine
48 */
49 public T sinh() {
50 return sinh;
51 }
52
53 /** Get the value of the hyperbolic cosine.
54 * @return value of the hyperbolic cosine
55 */
56 public T cosh() {
57 return cosh;
58 }
59
60 /** Compute hyperbolic sine and hyperbolic cosine of angles sum.
61 * @param schAlpha \((\sinh \alpha, \cosh \alpha)\)
62 * @param schBeta \((\sinh \beta, \cosh \beta)\)
63 * @param <S> the type of the field elements
64 * @return \((\sinh \alpha+\beta, \cosh \alpha+\beta)\)
65 */
66 public static <S extends CalculusFieldElement<S>> FieldSinhCosh<S> sum(final FieldSinhCosh<S> schAlpha, final FieldSinhCosh<S> schBeta) {
67 return new FieldSinhCosh<>(schAlpha.sinh.linearCombination(schAlpha.sinh, schBeta.cosh, schAlpha.cosh, schBeta.sinh),
68 schAlpha.sinh.linearCombination(schAlpha.cosh, schBeta.cosh, schAlpha.sinh, schBeta.sinh));
69 }
70
71 /** Compute hyperbolic sine and hyperbolic cosine of angles difference.
72 * @param schAlpha \((\sinh \alpha, \cosh \alpha)\)
73 * @param schBeta \((\sinh \beta, \cosh \beta)\)
74 * @param <S> the type of the field elements
75 * @return \((\sinh \alpha+\beta, \cosh \alpha-\beta)\)
76 */
77 public static <S extends CalculusFieldElement<S>> FieldSinhCosh<S> difference(final FieldSinhCosh<S> schAlpha, final FieldSinhCosh<S> schBeta) {
78 final S mShB = schBeta.sinh.negate();
79 return new FieldSinhCosh<>(schAlpha.sinh.linearCombination(schAlpha.sinh, schBeta.cosh, schAlpha.cosh, mShB),
80 schAlpha.sinh.linearCombination(schAlpha.cosh, schBeta.cosh, schAlpha.sinh, mShB));
81 }
82
83 }