On Thu, 8 May 2025 15:13:19 GMT, Raffaello Giulietti
wrote:
>> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
>> values arguments.
>> Further, add `unsignedMultiplyExact` methods as well.
>
> Raffaello Giulietti has updated the pull request incrementally with one
> a
> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
> values arguments.
> Further, add `unsignedMultiplyExact` methods as well.
Raffaello Giulietti has updated the pull request incrementally with one
additional commit since the last revision:
Added tests.
On Fri, 2 May 2025 17:49:54 GMT, Raffaello Giulietti
wrote:
> Yes, I'm familiar with both this Java code and the intrinsic code.
>
> Compare this with the much simpler proposed code. The checked multiplication
> `unsignedMultiplyExact` apparently performs two 64x64->64 multiplications,
> but
On Fri, 2 May 2025 17:53:12 GMT, Raffaello Giulietti
wrote:
>>> Anyway, since the pre-checks are not precise, that would lead to an
>>> implementation with a loop with checked, and another one with unchecked
>>> multiplications. I don't think this buys you anything.
>>
>> It serves to skip th
On Fri, 2 May 2025 17:26:21 GMT, fabioromano1 wrote:
>> @fabioromano1 Well, there are two checks. In one the product can overflow,
>> you'd need to convert one of the operands to `long`.
>>
>> Anyway, since the pre-checks are not precise, that would lead to an
>> implementation with a loop wit
On Fri, 2 May 2025 16:57:43 GMT, Shaojin Wen wrote:
>> src/java.base/share/classes/java/lang/Math.java line 3500:
>>
>>> 3498: return (n & 0b1) == 0 ? 1 : -1;
>>> 3499: }
>>> 3500:
>>
>> Suggestion:
>>
>>
>> if (x == 2) {
>> if (n >= Integer.SIZE - 1)
On Fri, 2 May 2025 17:30:55 GMT, fabioromano1 wrote:
>> Again, I don't think that `n == 1` is a frequent case which would make any
>> practical difference.
>>
>> As for the `bitLength` check, the product might overflow.
>> Further, `bitLength` might not be that cheap.
>> Finally, the test would
On Fri, 2 May 2025 16:53:39 GMT, Raffaello Giulietti
wrote:
> As for the `bitLength` check, the product might overflow. Further,
> `bitLength` might not be that cheap.
The current implementations of `bitLength()` calls `numberOfLeadingZeros`,
which are:
public static int numberOfLeadingZeros
On Fri, 2 May 2025 17:18:36 GMT, Raffaello Giulietti
wrote:
> Anyway, since the pre-checks are not precise, that would lead to an
> implementation with a loop with checked, and another one with unchecked
> multiplications. I don't think this buys you anything.
It serves to skip the checks in
On Fri, 2 May 2025 17:03:30 GMT, fabioromano1 wrote:
>> I don't think there's a quick, _precise_ pre-check that would ensure that
>> the loop can just use simple, unchecked `*` multiplications.
>>
>> Consider `unsignedPowExact(3L, 40)`, which does not overflow, versus
>> `unsignedPowExact(3L,
On Fri, 2 May 2025 16:45:28 GMT, Raffaello Giulietti
wrote:
> I don't think there's a quick, _precise_ pre-check that would ensure that the
> loop can just use simple, unchecked `*` multiplications.
>
> Consider `unsignedPowExact(3L, 40)`, which does not overflow, versus
> `unsignedPowExact(3
On Fri, 2 May 2025 16:04:18 GMT, fabioromano1 wrote:
>> Raffaello Giulietti has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Clearer and more complete spec of the *pow* methods.
>
> src/java.base/share/classes/java/lang/Math.java line 350
On Fri, 2 May 2025 16:26:48 GMT, fabioromano1 wrote:
>> @fabioromano1 Unless there's evidence that these cases are _very very_
>> common, there's no point in adding fast paths.
>> See this comment in `unsignedPowExact(long,int)`
>>
>>
>> /*
>> * To keep the code as simple as p
On Fri, 2 May 2025 16:06:42 GMT, fabioromano1 wrote:
>> Raffaello Giulietti has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Clearer and more complete spec of the *pow* methods.
>
> src/java.base/share/classes/java/lang/Math.java line 361
On Fri, 2 May 2025 16:23:24 GMT, Raffaello Giulietti
wrote:
>> src/java.base/share/classes/java/lang/Math.java line 3567:
>>
>>> 3565: return 1;
>>> 3566: }
>>> 3567: if (x == 0 || x == 1) {
>>
>> Suggestion:
>>
>> if (x == 0 || x == 1 || n == 1) {
>
> @fab
On Fri, 2 May 2025 16:07:31 GMT, fabioromano1 wrote:
>> Raffaello Giulietti has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> Clearer and more complete spec of the *pow* methods.
>
> src/java.base/share/classes/java/lang/Math.java line 356
On Fri, 2 May 2025 15:12:01 GMT, Raffaello Giulietti
wrote:
>> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
>> values arguments.
>> Further, add `unsignedMultiplyExact` methods as well.
>
> Raffaello Giulietti has updated the pull request incrementally with one
> a
On Fri, 2 May 2025 15:12:01 GMT, Raffaello Giulietti
wrote:
>> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
>> values arguments.
>> Further, add `unsignedMultiplyExact` methods as well.
>
> Raffaello Giulietti has updated the pull request incrementally with one
> a
> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
> values arguments.
> Further, add `unsignedMultiplyExact` methods as well.
Raffaello Giulietti has updated the pull request incrementally with one
additional commit since the last revision:
Clearer and more complete
On Fri, 2 May 2025 14:06:23 GMT, Per Minborg wrote:
>> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
>> values arguments.
>> Further, add `unsignedMultiplyExact` methods as well.
>
> Maybe it is too late, but shouldn't there be a better way to structure all
> these m
On Fri, 2 May 2025 11:47:32 GMT, Raffaello Giulietti
wrote:
> Add `powExact()` and `unsignedPowExact()` methods that operate on integer
> values arguments.
> Further, add `unsignedMultiplyExact` methods as well.
Maybe it is too late, but shouldn't there be a better way to structure all
these
21 matches
Mail list logo