Le lundi 09 juin 2014 à 04:41 -0700, 'Stéphane Laurent' via julia-users a écrit : > More seriously, are there really no case in Julia like that : > > > > Return float for negative b, integer otherwise ⟹ not > type-stable. > > > ? > > > Otherwise, a better solution is to return Rational for negative, and > Int for positive. Always returning Rational is not cool because we use > positive numbers more often than negative ones. > In this way, a^b would always return an exact result of the operation. > These operations belong to arithmetic on integer numbers, and > "rounding" has nothing to do here !
Well, in this logic, 1/2 should also return 1//2 instead of 0.5. I think most people don't need exact equality, that's why you need to ask explicitly if you want a Rational instead of a Float. > If i had a code performing some calculations on integer numbers, I > would be sad to discover a Float in the output in the case when I > forgot to handle the negative integers. > > > In this spirit, > > > 10^-2.0 > > is not the good reflex to have : it should be > > > (10//1)^-2 Yes, but then it's the programmer who gets to decide to use the second form when he expects a rational. Looks like the best solution since it's not what people most frequently need. Regards
