fr., 19.11.2010 kl. 10.24 -0800, skrev Julien Rioux: > Hi all, > > How can I tell the fcode printer to print integers and rationals as > reals? > > For example I would like the following output: > >>> expr = sqrt(1-x**2).series(x,n=20).removeO() > >>> print fcode(expr) > 1 - x**2/2 - x**4/8 - x**6/16 - 5*x**8/128 - 7*x**10/256 - > 21*x** > @ 12/1024 - 33*x**14/2048 - 429*x**16/32768 - 715*x**18/65536 > > (taken from http://docs.sympy.org/dev/modules/printing.html) > > this is wrong in most cases since in in Fortran "/2" is integer > division and it should be replaced by "/2.d0", etc. > > a flag fcode(expr,assign_as="real") would be most useful > > thanks, > Julien >
Thanks for spotting this. I think the code printers should by default assume floating point division, as the generated code would then match more closely the rational numbers in the corresponding SymPy expression. I'd say you should file a bug. Are you sure there is really need for an option flag? Unless there is a known case where integer truncation is the correct thing, I think we should prefer to keep the interface simple, and use floating point division indiscriminately. Øyvind -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
