commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <>
Subject Re: [Math] Deprecate "pow(int, long)" and "pow(long,long)" in "ArithmeticUtils"
Date Tue, 29 Oct 2013 22:04:47 GMT
On Tue, 29 Oct 2013 20:14:19 +0100, Luc Maisonobe wrote:
> Le 29/10/2013 15:00, Gilles a écrit :
>> Hello.
> Hi Gilles,
>> While working on MATH-1047, I wondered about the usefulness of those
>> two methods. Excluding the trivial case (base=|1|), the result will
>> overflow as soon as the exponent is larger than 31, when base=|2|,
>> and sooner the larger the base.
>> Hence, the methods amount to syntactic sugar to spare a cast from
>> a "long" to an "int" exponent.
>> IMO, this is not worth the number of source code lines.
>> Unless there is an objection, I propose to deprecate those methods
>> in 3.3 and remove them in 4.0.
> There were three main reasons for this method :
>  - in many cases, very low (and fixed) exponents are often 
> encountered
>    (say exponents up to half a dozen or so),
>  - computation with long in Java bytecode is not done the same way as
>    int because it needs two successive variable slots and requires
>    successive memory loading, and thus is slower (of course, this 
> effect
>    disappears when the JIT compiler converts everything to native 
> code
>    if the processor is 64 bits),
>  - forcing the user to add a cast clutters the code.
> As always, your mileage may vary.

I must be missing something (sorry!): I propose to remove the methods 
the exponent is a "long", and as I understand it, you give reasons for 
1. Why would one want/need to use a "long" for a _small_ value?
2. Moreover you say that using a "long" is slower; thus, a second 
reason for
    not calling those methods.
3. A cast would only be necessary if the user chooses to use a "long" 
    even if it is neither necessary (cf 1.) nor desirable (cf. 2.).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message