Describe the feature
Create a curated compilation of the new java.lang.Math methods introduced in Java 25 for java.evolved, using the site's old-approach versus modern-approach format. Cover all three API families / seven overloads below, with practical examples and clear explanations of overflow and unsigned arithmetic.
| API family |
New overloads in Java 25 |
What to showcase |
Math.powExact |
powExact(int, int), powExact(long, int) |
Exact integer exponentiation with overflow detection instead of a hand-written checked multiplication loop. |
Math.unsignedPowExact |
unsignedPowExact(int, int), unsignedPowExact(long, int) |
Exponentiation treating the base and result as unsigned values, with unsigned-range overflow detection. |
Math.unsignedMultiplyExact |
unsignedMultiplyExact(int, int), unsignedMultiplyExact(long, int), unsignedMultiplyExact(long, long) |
Checked unsigned multiplication without custom unsigned overflow checks or a BigInteger workaround. |
All seven overloads are documented as Since: 25. Keep the compilation focused on actual Java 25 additions: Math.clamp is from Java 21 and already has a pattern at content/datetime/math-clamp.yaml; ceiling division and other older Math improvements should only appear as related reading, not as Java 25 additions.
Illustrative modern examples
int power = Math.powExact(3, 10); // 59049
int unsignedPower = Math.unsignedPowExact(2, 31);
String powerText = Integer.toUnsignedString(unsignedPower); // "2147483648"
long unsignedProduct = Math.unsignedMultiplyExact(Long.MAX_VALUE, 2L);
String productText = Long.toUnsignedString(unsignedProduct); // "18446744073709551614"
Content requirements
- Present a focused old/modern comparison for each family, with a shared compilation overview and related links. Prefer existing content conventions rather than introducing a new page system.
- Use a repeated
Math.multiplyExact loop as a behavior-preserving baseline for signed powers. Explain why casting Math.pow is not equivalent: it uses floating-point arithmetic and does not provide the same exact integer overflow contract.
- For unsigned examples, explain that Java still stores the result in signed
int/long primitives; negative stored values may represent valid unsigned results. Show Integer.toUnsignedString and Long.toUnsignedString when displaying them.
- Explain that the
Exact methods throw ArithmeticException on overflow. Both power families also throw ArithmeticException for a negative exponent and return 1 for exponent zero, including a zero base.
- Cover boundaries: the largest representable successful result, the first overflowing result, zero, negative signed bases, and unsigned inputs with their high bit set. Clarify that the exponent remains a signed
int and must be non-negative.
- Include the mixed-width
unsignedMultiplyExact(long, int) overload; its int argument is interpreted as unsigned, not as an ordinary signed multiplier.
- Avoid unsupported performance claims; the primary benefits are explicit intent, less custom arithmetic, and reliable overflow detection.
Acceptance criteria
Official references
Why would this be useful?
These additions make exact integer powers and checked unsigned arithmetic much easier to express, but they are easy to miss among Java 25's larger language and runtime changes. A compilation gives readers a practical overview of what is genuinely new, shows which manual implementations can be replaced, and makes important overflow and unsigned-representation pitfalls visible.
Alternatives considered
- A general roundup of Math improvements available on Java 25, including older APIs such as
clamp and ceilDiv. Useful separately, but it would blur the distinction between APIs introduced in Java 25 and APIs merely available on it.
- One large pattern containing every overload. Prefer focused comparisons for the three families, linked together as a compilation, to keep examples readable.
- Linking only to Javadoc. Authoritative references are essential, but do not replace java.evolved's practical before/after examples.
Describe the feature
Create a curated compilation of the new
java.lang.Mathmethods introduced in Java 25 for java.evolved, using the site's old-approach versus modern-approach format. Cover all three API families / seven overloads below, with practical examples and clear explanations of overflow and unsigned arithmetic.Math.powExactpowExact(int, int),powExact(long, int)Math.unsignedPowExactunsignedPowExact(int, int),unsignedPowExact(long, int)Math.unsignedMultiplyExactunsignedMultiplyExact(int, int),unsignedMultiplyExact(long, int),unsignedMultiplyExact(long, long)BigIntegerworkaround.All seven overloads are documented as Since: 25. Keep the compilation focused on actual Java 25 additions:
Math.clampis from Java 21 and already has a pattern atcontent/datetime/math-clamp.yaml; ceiling division and other older Math improvements should only appear as related reading, not as Java 25 additions.Illustrative modern examples
Content requirements
Math.multiplyExactloop as a behavior-preserving baseline for signed powers. Explain why castingMath.powis not equivalent: it uses floating-point arithmetic and does not provide the same exact integer overflow contract.int/longprimitives; negative stored values may represent valid unsigned results. ShowInteger.toUnsignedStringandLong.toUnsignedStringwhen displaying them.Exactmethods throwArithmeticExceptionon overflow. Both power families also throwArithmeticExceptionfor a negative exponent and return1for exponent zero, including a zero base.intand must be non-negative.unsignedMultiplyExact(long, int)overload; itsintargument is interpreted as unsigned, not as an ordinary signed multiplier.Acceptance criteria
jdkVersion: "25"andsupport.state: availablefor new patterns.validatepatternchanges.javaand the new proofs successfully.social/queue.txtorsocial/state.yaml, and do not commit generated site output.Official references
powExact(int, int)andpowExact(long, int)unsignedPowExact(int, int)andunsignedPowExact(long, int)unsignedMultiplyExact(int, int),unsignedMultiplyExact(long, int), andunsignedMultiplyExact(long, long)Why would this be useful?
These additions make exact integer powers and checked unsigned arithmetic much easier to express, but they are easy to miss among Java 25's larger language and runtime changes. A compilation gives readers a practical overview of what is genuinely new, shows which manual implementations can be replaced, and makes important overflow and unsigned-representation pitfalls visible.
Alternatives considered
clampandceilDiv. Useful separately, but it would blur the distinction between APIs introduced in Java 25 and APIs merely available on it.