An AskSage 
question<http://ask.sagemath.org/question/1467/why-is-3e1-not-equivalent-to-30> 
brings 
up a good point: shouldn't scientific notation work for integers? 3e1 
returns a RealLiteral, not an Integer. Python also does this; 3e1 is a 
float. But wouldn't it be better if the preparser detected whether the 
output will be an integer, and if so, cast it as such? All it would have to 
do is check whether the exponent was greater or equal to the length of the 
decimal part of the coefficient. For example:

def integral_scientific(num):
     coefficient, exponent = num.split('e')
     if RealNumber(exponent) >= (len(coefficient.split('.')[1]) if '.' in 
coefficient else 0):
         return Integer(RealNumber(coefficient) * 10 ** Integer(exponent))
     else:
         return RealNumber(coefficient) * 10 ** Integer(exponent)

sage: integral_scientific('3.33e10')
33300000000
sage: integral_scientific('3.33e1') 
33.3000000000000
sage: integral_scientific('3.00e1')
30.0000000000000
sage: integral_scientific('3543e1')
35430

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to