001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.math3; 018 019import org.apache.commons.math3.exception.MathArithmeticException; 020import org.apache.commons.math3.exception.NullArgumentException; 021 022 023/** 024 * Interface representing <a href="http://mathworld.wolfram.com/Field.html">field</a> elements. 025 * @param <T> the type of the field elements 026 * @see Field 027 * @since 2.0 028 */ 029public interface FieldElement<T> { 030 031 /** Compute this + a. 032 * @param a element to add 033 * @return a new element representing this + a 034 * @throws NullArgumentException if {@code a} is {@code null}. 035 */ 036 T add(T a) throws NullArgumentException; 037 038 /** Compute this - a. 039 * @param a element to subtract 040 * @return a new element representing this - a 041 * @throws NullArgumentException if {@code a} is {@code null}. 042 */ 043 T subtract(T a) throws NullArgumentException; 044 045 /** 046 * Returns the additive inverse of {@code this} element. 047 * @return the opposite of {@code this}. 048 */ 049 T negate(); 050 051 /** Compute n × this. Multiplication by an integer number is defined 052 * as the following sum 053 * <center> 054 * n × this = ∑<sub>i=1</sub><sup>n</sup> this. 055 * </center> 056 * @param n Number of times {@code this} must be added to itself. 057 * @return A new element representing n × this. 058 */ 059 T multiply(int n); 060 061 /** Compute this × a. 062 * @param a element to multiply 063 * @return a new element representing this × a 064 * @throws NullArgumentException if {@code a} is {@code null}. 065 */ 066 T multiply(T a) throws NullArgumentException; 067 068 /** Compute this ÷ a. 069 * @param a element to divide by 070 * @return a new element representing this ÷ a 071 * @throws NullArgumentException if {@code a} is {@code null}. 072 * @throws MathArithmeticException if {@code a} is zero 073 */ 074 T divide(T a) throws NullArgumentException, MathArithmeticException; 075 076 /** 077 * Returns the multiplicative inverse of {@code this} element. 078 * @return the inverse of {@code this}. 079 * @throws MathArithmeticException if {@code this} is zero 080 */ 081 T reciprocal() throws MathArithmeticException; 082 083 /** Get the {@link Field} to which the instance belongs. 084 * @return {@link Field} to which the instance belongs 085 */ 086 Field<T> getField(); 087}