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.math3; 18 19 import org.apache.commons.math3.exception.MathArithmeticException; 20 import org.apache.commons.math3.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 */ add(T a)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 */ subtract(T a)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 */ negate()49 T negate(); 50 51 /** Compute n × this. Multiplication by an integer number is defined 52 * as the following sum 53 * <center> 54 * n × this = ∑<sub>i=1</sub><sup>n</sup> this. 55 * </center> 56 * @param n Number of times {@code this} must be added to itself. 57 * @return A new element representing n × this. 58 */ multiply(int n)59 T multiply(int n); 60 61 /** Compute this × a. 62 * @param a element to multiply 63 * @return a new element representing this × a 64 * @throws NullArgumentException if {@code a} is {@code null}. 65 */ multiply(T a)66 T multiply(T a) throws NullArgumentException; 67 68 /** Compute this ÷ a. 69 * @param a element to divide by 70 * @return a new element representing this ÷ a 71 * @throws NullArgumentException if {@code a} is {@code null}. 72 * @throws MathArithmeticException if {@code a} is zero 73 */ divide(T a)74 T divide(T a) throws NullArgumentException, MathArithmeticException; 75 76 /** 77 * Returns the multiplicative inverse of {@code this} element. 78 * @return the inverse of {@code this}. 79 * @throws MathArithmeticException if {@code this} is zero 80 */ reciprocal()81 T reciprocal() throws MathArithmeticException; 82 83 /** Get the {@link Field} to which the instance belongs. 84 * @return {@link Field} to which the instance belongs 85 */ getField()86 Field<T> getField(); 87 } 88