Skip to content

[Feature] Showcase the new Java 25 Math methods #228

Description

@brunoborges

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

  • All seven overloads are covered across the three families and labeled Java 25+, with jdkVersion: "25" and support.state: available for new patterns.
  • Each new pattern follows the content schema: independently generated UUID, matching slug/category, navigation order, registered tags, exactly three modern benefits, exactly three valid related targets, and official documentation links.
  • Add runnable Java 25 JBang proof files for the modern examples and partial content translations for every registered non-English locale.
  • Verify documented results and exception behavior on Java 25; keep proof files consistent with the repository's modern-code-only, no-assertions convention.
  • Rebuild every locale and run validatepatternchanges.java and the new proofs successfully.
  • Generate and commit each new pattern's social tweet draft; do not modify social/queue.txt or social/state.yaml, and do not commit generated site output.

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions