mabshoff wrote:
> 
> 
> On Nov 27, 12:34 pm, "William Stein" <[EMAIL PROTECTED]> wrote:
>> On Thu, Nov 27, 2008 at 12:30 PM, mabshoff <[EMAIL PROTECTED]> wrote:
>>
>>> On Nov 27, 11:24 am, Jason Grout <[EMAIL PROTECTED]> wrote:
>>>> Ronan Paixão wrote:
>>>>> I just found a problem with Integer(). It doesn't seem to work fine with
>>>>> float strings.
>>>>> Those work fine:
>>>>> Integer("1")
>>>>> Integer(1.)
>>>>> But this doesn't:
>>>>> Integer("1.")
>>>> More data:
>>>> Integer(RR('1.')) works
>>>> Integer(RR('1.0')) works
>>>> Integer('1.0') doesn't work
>>>> I think that at least '1.' ought to be converted to an integer.
>>> Seems like a reasonable request. I would even allow ("$FOO.0"). Care
>>> to open a ticket?
>> I strongly disagree, since pure Python does not allow this, and
>> Sage's string conversion of integers should be consistent with that:
> 
> Ok, that is certainly a killer argument against this.
> 
> <SNIP>
> 
> But how about some functions that do convert "1.0" and "1." to an
> Integer object? I have no good suggestion how to name there or where
> to stick them, but it seems that they could come in useful. One could
> always use regular expressions to transform the string since this is
> all about getting pexepct output from Scilab to play nice with Sage.


Since {RR,QQ}->Integer *does* work, you could do:

Integer(sage_eval('1.'))

Integer(sage_eval('2/2'))

Integer(sage_eval('1.0'))

or something like:

try:
    return Integer(RR(my_string))
except TypeError:
    return Integer(QQ(my_string))


Of course, using sage_eval for this is a bit like using a sledgehammer 
to hammer a nail.

Jason


--~--~---------~--~----~------------~-------~--~----~
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://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to