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 */
017 package org.apache.commons.math3;
018
019 import org.apache.commons.math3.exception.MathArithmeticException;
020 import 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 * @version $Id: FieldElement.java 1416643 2012-12-03 19:37:14Z tn $
028 * @since 2.0
029 */
030 public interface FieldElement<T> {
031
032 /** Compute this + a.
033 * @param a element to add
034 * @return a new element representing this + a
035 * @throws NullArgumentException if {@code addend} is {@code null}.
036 */
037 T add(T a) throws NullArgumentException;
038
039 /** Compute this - a.
040 * @param a element to subtract
041 * @return a new element representing this - a
042 * @throws NullArgumentException if {@code a} is {@code null}.
043 */
044 T subtract(T a) throws NullArgumentException;
045
046 /**
047 * Returns the additive inverse of {@code this} element.
048 * @return the opposite of {@code this}.
049 */
050 T negate();
051
052 /** Compute n × this. Multiplication by an integer number is defined
053 * as the following sum
054 * <center>
055 * n × this = ∑<sub>i=1</sub><sup>n</sup> this.
056 * </center>
057 * @param n Number of times {@code this} must be added to itself.
058 * @return A new element representing n × this.
059 */
060 T multiply(int n);
061
062 /** Compute this × a.
063 * @param a element to multiply
064 * @return a new element representing this × a
065 * @throws NullArgumentException if {@code a} is {@code null}.
066 */
067 T multiply(T a) throws NullArgumentException;
068
069 /** Compute this ÷ a.
070 * @param a element to add
071 * @return a new element representing this ÷ a
072 * @throws NullArgumentException if {@code a} is {@code null}.
073 * @throws MathArithmeticException if {@code a} is zero
074 */
075 T divide(T a) throws NullArgumentException, MathArithmeticException;
076
077 /**
078 * Returns the multiplicative inverse of {@code this} element.
079 * @return the inverse of {@code this}.
080 * @throws MathArithmeticException if {@code this} is zero
081 */
082 T reciprocal() throws MathArithmeticException;
083
084 /** Get the {@link Field} to which the instance belongs.
085 * @return {@link Field} to which the instance belongs
086 */
087 Field<T> getField();
088 }