1 /* 2 * Licensed to the Apache Software Foundation (ASF) 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 ASF 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 * http://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.apache.commons.math4.legacy.core; 18 19 import org.apache.commons.math4.legacy.exception.MathArithmeticException; 20 import org.apache.commons.math4.legacy.exception.NullArgumentException; 21 22 23 /** 24 * Interface representing <a href="http://mathworld.wolfram.com/Field.html">field</a> elements. 25 * @param <T> the type of the field elements 26 * @see Field 27 * @since 2.0 28 */ 29 public interface FieldElement<T> { 30 31 /** Compute this + a. 32 * @param a element to add 33 * @return a new element representing this + a 34 * @throws NullArgumentException if {@code a} is {@code null}. 35 */ 36 T add(T a) throws NullArgumentException; 37 38 /** Compute this - a. 39 * @param a element to subtract 40 * @return a new element representing this - a 41 * @throws NullArgumentException if {@code a} is {@code null}. 42 */ 43 T subtract(T a) throws NullArgumentException; 44 45 /** 46 * Returns the additive inverse of {@code this} element. 47 * @return the opposite of {@code this}. 48 */ 49 T negate(); 50 51 /** Compute n × this. Multiplication by an integer number is defined 52 * as the following sum: 53 * <p>n × this = ∑<sub>i=1</sub><sup>n</sup> this. 54 * @param n Number of times {@code this} must be added to itself. 55 * @return A new element representing n × this. 56 */ 57 T multiply(int n); 58 59 /** Compute this × a. 60 * @param a element to multiply 61 * @return a new element representing this × a 62 * @throws NullArgumentException if {@code a} is {@code null}. 63 */ 64 T multiply(T a) throws NullArgumentException; 65 66 /** Compute this ÷ a. 67 * @param a element to divide by 68 * @return a new element representing this ÷ a 69 * @throws NullArgumentException if {@code a} is {@code null}. 70 * @throws MathArithmeticException if {@code a} is zero 71 */ 72 T divide(T a) throws NullArgumentException, MathArithmeticException; 73 74 /** 75 * Returns the multiplicative inverse of {@code this} element. 76 * @return the inverse of {@code this}. 77 * @throws MathArithmeticException if {@code this} is zero 78 */ 79 T reciprocal() throws MathArithmeticException; 80 81 /** Get the {@link Field} to which the instance belongs. 82 * @return {@link Field} to which the instance belongs 83 */ 84 Field<T> getField(); 85 }