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.numbers.field; 18 19 /** 20 * Interface representing a <a href="http://mathworld.wolfram.com/Field.html">field</a>. 21 * 22 * @param <T> Type of the field elements. 23 */ 24 public interface Field<T> { 25 /** 26 * @param a Field element. 27 * @param b Field element. 28 * @return {@code a + b}. 29 */ 30 T add(T a, T b); 31 32 /** 33 * @param a Field element. 34 * @param b Field element. 35 * @return {@code a - b}. 36 */ 37 T subtract(T a, T b); 38 39 /** 40 * @param a Field element. 41 * @return {@code -a}. 42 */ 43 T negate(T a); 44 45 /** 46 * @param a Field element. 47 * @param n Number of times {@code a} must be added to itself. 48 * @return {@code n a}. 49 */ 50 T multiply(int n, T a); 51 52 /** 53 * @param a Field element. 54 * @param b Field element. 55 * @return {@code a * b}. 56 */ 57 T multiply(T a, T b); 58 59 /** 60 * @param a Field element. 61 * @param b Field element. 62 * @return <code>a * b<sup>-1</sup></code>. 63 */ 64 T divide(T a, T b); 65 66 /** 67 * @param a Field element. 68 * @return <code>a<sup>-1</sup></code>. 69 */ 70 T reciprocal(T a); 71 72 /** 73 * @return the field element {@code 1} such that for all {@code a}, 74 * {@code 1 * a == a}. 75 */ 76 T one(); 77 78 /** 79 * @return the field element {@code 0} such that for all {@code a}, 80 * {@code 0 + a == a}. 81 */ 82 T zero(); 83 }