diff a/src/java.base/share/classes/java/lang/Integral.java b/src/java.base/share/classes/java/lang/Integral.java --- /dev/null +++ b/src/java.base/share/classes/java/lang/Integral.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * Indicates an integral type that supports: + *
In mathematical terms, various kinds of algebraic structures + * support the operations modeled by this interface. For example, + * integers with Euclidean division support the operations in question + * as do algebraic fields. Commonly used algebraic fields + * include rational numbers, real numbers, and complex numbers. A + * field has a set of values and operations on those values. The + * operations have various properties known as the field + * axioms. These include associativity of addition and + * multiplication, commutativity of addition and multiplication, and + * multiplication distributing over addition. Fields can be + * {@linkplain OrderedComparison ordered} (rational numbers, real + * numbers) or unordered (complex numbers). + * + *
Types used to approximate a field, such as a floating-point type + * used to approximate real numbers, will both approximate the set of + * values of the field and the set of properties over the supported + * operations. In particular, properties like associativity of + * addition are not expected to hold for a floating-point + * type. + * + *
The intention of this interface is to enable types that
+ * customarily support numerical notions of addition, subtraction,
+ * multiplication and division to enjoy operator overloading syntax
+ * even if the underlying algebraic properties do not hold because of
+ * limitations in approximation.
+ *
+ * @param Special Cases:
+ * Say something about defining witnesses for the wrapper classes.
+ *
+ * @apiNote
+ * Fun fact: monoids are subcomponents of richer algebraic structures
+ * like rings and fields.
+ *
+ * Say something about expected associativity of add operation?
+ * A zero element is one where:
+ *
+ *
+ *
+ * @param operand the floating-point value whose ulp is to be returned
+ * @return the size of an ulp of the argument
+ */
+ SFP ulp(SFP operand);
+
+ /**
+ * Returns a hexadecimal string representation of the argument.
+ *
+ * @param operand the value to be converted.
+ * @return a hex string representation of the argument.
+ *
+ */
+ String toHexString(SFP operand);
+
+ // Possible TODO:
+ // scaleBy
+ // nextUp/nextDown
+}
diff a/src/java.base/share/classes/java/lang/UnsignedInt.java b/src/java.base/share/classes/java/lang/UnsignedInt.java
--- /dev/null
+++ b/src/java.base/share/classes/java/lang/UnsignedInt.java
@@ -0,0 +1,434 @@
+/*
+ * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.lang;
+
+import java.lang.runtime.Monoid;
+
+/**
+ * Unsigned 32-bit integers.
+ */
+public class /*value record*/ UnsignedInt {
+ private int value;
+
+ private UnsignedInt(int value) {
+ this.value = value;
+ }
+
+ /**
+ * An {@code Integral} witness for {@code UnsignedInt}.
+ */
+ // Fails at runtime if Integral is used instead of Monoid
+ public static __witness Monoid
+ *
+ * Besides occurring in numerical setting, a monoid can be defined
+ * in other contexts as well. For example, string concatenation with
+ * the empty string ({@code ""}) serving as the zero element forms a
+ * monoid.
+ *
+ * @param
+ * monoid.add(element, monoid.zero()) ==
+ * monoid.add(monoid.zero(), element) ==
+ * element
+ *