I have actually been debating about the best way to handle this. (This is in fact one of the reasons I didn't finish the Wiki yet...) However, I think that 2**8 is not an integer is severely counter- intuitive. The ambiguity here is due to the fact, as you mentioned, C doesn't have the notion of pow() for ints. Although C implicitly coerces ints to floats in general, no (non-functional) arithmetic operations in C return a different data type then their arguments.
I am leaning towards disabling the functionality altogether. If the user wants to do it one way or the other, it will be pretty easy to make it explicit. Some of the operations (e.g. bit operations) are integer-only, this would be float-only. I'd have to go through our codebase and make sure nothing breaks, but I doubt anything would. Any comments? - Robert On Feb 20, 2007, at 4:49 PM, didier deshommes wrote: > ---------- Forwarded message ---------- > From: Greg Ewing <[EMAIL PROTECTED]> > Date: Feb 20, 2007 7:10 PM > Subject: Re: [Pyrex] Integer exponentiation returns a double > To: didier deshommes <[EMAIL PROTECTED]> > Cc: [EMAIL PROTECTED] > > > didier deshommes wrote: >> Robert >> Bradshaw found that when a and b are cdef'ed as integers, the result >> of a**b is a double. > > Pyrex's philosophy is that when operating on two things > both defined as C data types, the operation that should > be done is the one that makes the most sense from a > C point of view. In the case of **, this means translating > it into a call to the C pow() function. > > Since C doesn't provide any integer-only power operation, > the only alternative would be to convert them to Python > ints and return a Python int or long. Since that's an > expensive thing to do, I think it's better if the programmer > needs to be explicit about it. > > To avoid misleading people into creating bugs, it might > be better to disallow ** on C ints altogether, although > that would be surprising in another way, since C ints are > normally promoted to floats automatically wherever > appropriate. > > -- > Greg > > > > On Feb 20, 4:48 pm, "didier deshommes" <[EMAIL PROTECTED]> wrote: >> On 2/20/07, Robert Bradshaw <[EMAIL PROTECTED]> wrote: >> >> >> >>> Last night we discovered a really bad bug in SageX when doing a**b >>> (with a, b cdef'ed). >> >> Robert, >> I've forwarded this to the pyrex mailing list >> >> didier > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/ -~----------~----~----~----~------~----~------~--~---