It doesn't, but I think it should. The string printer (sstr) doesn't have any precision settings, because it just prints floats at the precision that they are. But ccode() always prints floats with enough digits for C. It should be possible to override this, and the precision option seems like the best way to do this.
The current behavior is also incorrect in another way, which is that it always uses 17 digits of precision for Float, even though they default to 15 (also I'm unclear why it is using 17). It should really be using no more digits than the Float already has. This is even worse if you explicitly evalf floats to lower than the default 15 digits. If this worked correctly, you would be able to work around your issue by simply calling evalf(8) on your expression before calling ccode(). Aaron Meurer On Wed, Dec 16, 2020 at 2:21 PM [email protected] <[email protected]> wrote: > > The documentation (https://docs.sympy.org/latest/modules/printing.html) says > the precision parameter is for "numbers such as pi" so I wasn't sure if it > applied to certain constants or any floating point values. > > On Wednesday, December 16, 2020 at 4:11:43 PM UTC-5 [email protected] wrote: >> >> This looks like a bug. The precision parameter is being ignored. >> >> Aaron Meurer >> >> On Wed, Dec 16, 2020 at 11:51 AM [email protected] >> <[email protected]> wrote: >> > >> > Hi - >> > >> > Is it possible to set the precision of printed floating point values when >> > using ccode, cxxcode, etc? Using the 'precision' parameter does not seem >> > to do anything. >> > >> > For instance, the following: >> > T = sym.Symbol('T') >> > f = 0.00437791*T**2 >> > print(sym.cxxcode(f, precision=8)) >> > >> > produces: >> > >> > 0.0043779099999999996*std::pow(T, 2) >> > >> > Thanks. >> > >> > - Jesse >> > >> > >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "sympy" group. >> > To unsubscribe from this group and stop receiving emails from it, send an >> > email to [email protected]. >> > To view this discussion on the web visit >> > https://groups.google.com/d/msgid/sympy/adfc7377-602e-4442-b5c3-aebd3d2c529dn%40googlegroups.com. > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/8a1174cb-4eb3-4d90-9494-6d2dce5bf622n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6KNwXn2ghwbfxHWZSM7NMv%2Bi_9fe2dddQyS_z0Axa2-3A%40mail.gmail.com.
