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.math;
018    
019    
020    /**
021     * Interface representing <a href="http://mathworld.wolfram.com/Field.html">field</a> elements.
022     * @param <T> the type of the field elements
023     * @see Field
024     * @version $Id: FieldElement.java 1180312 2011-10-08 04:21:00Z celestin $
025     * @since 2.0
026     */
027    public interface FieldElement<T> {
028    
029        /** Compute this + a.
030         * @param a element to add
031         * @return a new element representing this + a
032         */
033        T add(T a);
034    
035        /** Compute this - a.
036         * @param a element to subtract
037         * @return a new element representing this - a
038         */
039        T subtract(T a);
040    
041        /**
042         * Returns the additive inverse of {@code this} element.
043         * @return the opposite of {@code this}.
044         */
045        T negate();
046    
047        /** Compute n &times; this. Multiplication by an integer number is defined
048         * as the following sum
049         * <center>
050         * n &times; this = &sum;<sub>i=1</sub><sup>n</sup> this.
051         * </center>
052         * @param n Number of times {@code this} must be added to itself.
053         * @return A new element representing n &times; this.
054         */
055        T multiply(int n);
056    
057        /** Compute this &times; a.
058         * @param a element to multiply
059         * @return a new element representing this &times; a
060         */
061        T multiply(T a);
062    
063        /** Compute this &divide; a.
064         * @param a element to add
065         * @return a new element representing this &divide; a
066         * @exception ArithmeticException if a is the zero of the
067         * additive operation (i.e. additive identity)
068         */
069        T divide(T a) throws ArithmeticException;
070    
071        /**
072         * Returns the multiplicative inverse of {@code this} element.
073         * @return the inverse of {@code this}.
074         */
075        T reciprocal();
076    
077        /** Get the {@link Field} to which the instance belongs.
078         * @return {@link Field} to which the instance belongs
079         */
080        Field<T> getField();
081    }