On Wed, 8 Oct 2025 18:18:50 GMT, Roger Riggs <[email protected]> wrote:

> Omit minusSaturating, I think subtraction is much less common and even more 
> so to exceed the negative range.
> The caller can negate their argument and use plus if that's needed.

On the one hand, I also don't think we need `minusSaturating` as far as the 
typical use case is concerned. On the other hand, negating durations is a 
tricky business. Although, it's not a real use case, negating the minimum 
duration will cause `ArithmeticException`:


jshell> Duration.ofSeconds(Long.MIN_VALUE, 0).negated()
|  Exception java.lang.ArithmeticException: Exceeds capacity of Duration: 
9223372036854775808000000000
|        at Duration.create (Duration.java:1056)
|        at Duration.multipliedBy (Duration.java:995)
|        at Duration.negated (Duration.java:1074)
|        at (#2:1)


So one cannot implement `i.minusSaturaring(Duration.ofSeconds(Long.MIN_VALUE, 
0))` as `i.plusSaturating(Duration.ofSeconds(Long.MIN_VALUE, 0).negated())`.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27549#discussion_r2414764263

Reply via email to