NUMBERS-51: API for basic operations.
Project: http://git-wip-us.apache.org/repos/asf/commons-numbers/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-numbers/commit/518b58ab Tree: http://git-wip-us.apache.org/repos/asf/commons-numbers/tree/518b58ab Diff: http://git-wip-us.apache.org/repos/asf/commons-numbers/diff/518b58ab Branch: refs/heads/master Commit: 518b58abf5f4716c5459fc52c7f52d17ef3d71fd Parents: 67446f4 Author: Gilles Sadowski <[email protected]> Authored: Tue Dec 26 02:36:11 2017 +0100 Committer: Gilles Sadowski <[email protected]> Committed: Tue Dec 26 02:36:11 2017 +0100 ---------------------------------------------------------------------- .../apache/commons/numbers/core/Addition.java | 39 +++++++++++++++ .../commons/numbers/core/Multiplication.java | 39 +++++++++++++++ .../commons/numbers/core/NativeOperators.java | 51 ++++++++++++++++++++ 3 files changed, 129 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/518b58ab/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Addition.java ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Addition.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Addition.java new file mode 100644 index 0000000..dff3887 --- /dev/null +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Addition.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.numbers.core; + +/** + * Addition. + * + * <T> Type of elements. + */ +public interface Addition<T> { + /** + * Binary addition. + * + * @param a Element. + * @return {@code this + a}. + */ + T add(T a); + + /** + * Additive inverse. + * + * @return {@code -this}. + */ + T negate(); +} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/518b58ab/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Multiplication.java ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Multiplication.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Multiplication.java new file mode 100644 index 0000000..7b1df66 --- /dev/null +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Multiplication.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.numbers.core; + +/** + * Multiplication. + * + * <T> Type of elements. + */ +public interface Multiplication<T> { + /** + * Binary multiplication. + * + * @param a Element. + * @return {@code this * a}. + */ + T multiply(T a); + + /** + * Multiplicative inverse. + * + * @return <code>this<sup>-1</sup></code>. + */ + T reciprocal(); +} http://git-wip-us.apache.org/repos/asf/commons-numbers/blob/518b58ab/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NativeOperators.java ---------------------------------------------------------------------- diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NativeOperators.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NativeOperators.java new file mode 100644 index 0000000..fec6cff --- /dev/null +++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/NativeOperators.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.numbers.core; + +/** + * Operators that can be implemented in a more performant way + * using the language constructs. + * + * <T> Type of elements. + */ +public interface NativeOperators<T> + extends Addition<T>, + Multiplication<T> { + /** + * Binary subtraction. + * + * @param a Element. + * @return {@code this - a}. + */ + T subtract(T a); + + /** + * Binary division. + * + * @param a Element. + * @return {@code this / a}. + */ + T divide(T a); + + /** + * Repeated addition. + * + * @param n Number of times to add {@code this} to itself. + * @return {@code n * this}. + */ + T multiply(int n); +}
