julia> (10//1)^(-2)

1//100


Would it be problematic to return a rational for  (a::Integer)^(b::Integer) 
?



Le dimanche 8 juin 2014 21:53:45 UTC+2, Stefan Karpinski a écrit :
>
> There are three obvious options for (a::Integer)^(b::Integer):
>
>    1. Always return an integer ⟹ fails for negative b.
>    2. Always return a float ⟹ a^2 is not the same as a*a.
>    3. Return float for negative b, integer otherwise ⟹ not type-stable. 
>
> As you can see, all of these choices are problematic. The first one, which 
> is what we currently do, seems to be the least problematic. One somewhat 
> crazier option that has been proposed is making ^- as in a^-b parse as a 
> different operator and have a^b return an integer for integer arguments but 
> a^-b return a float for integer arguments. This would have the unfortunate 
> effect of making a^-b different from a^(-b).
>
>
> On Sat, Jun 7, 2014 at 12:41 PM, Daniel Jones <[email protected] 
> <javascript:>> wrote:
>
>>  I'd definitely be in favor of '^' converting to float, like '/', having 
>> fallen 
>> for than recently 
>> <https://github.com/JuliaLang/Color.jl/commit/c3d05dd2b94f0d38b64ef86022accdfec886a673>
>> .
>>   
>> On Sat, Jun 7, 2014, at 12:53 AM, Ivar Nesje wrote:
>> >
>> > There has also been discussion on whether ^(a::Integer,b::Integer) 
>> should
>> > return a Float64 by default, and defer to pow() like /(a::Integer,
>> > b::Integer) defers to div(). The problem is that many people like the
>> > 10^45 vs 1e45 notation for large integers vs float constants, and we can
>> > make it a clean error instead of a silent bug.
>>  
>>  
>
>

Reply via email to