I want to take the output in fortran form but written in double precision notation. For example,

exp=1 + 8*as^2*Log[2*x]

which gives

FortranForm[exp]=1 + 8*as**2*Log(2*x)

but I want as

FortranForm[exp]=1.0D0 + 8.0D0*as**2.0D0*dLog(2.0D0*x)

Basically everything is written in double precision. I can always do replacement in mathematica file, eg.

exp /. {Log->dLog} etc. 

However I was wondering is there any more intrinsic way to have the output format.

  • $\begingroup$ CForm and FortranForm don't deal with most function names. They're left up to you. CForm[Log[x]] gives Log(x) which isn't a standard C function. A common solution with C is to #define Log whateverYouWant. The other possible solution is the replace you mention. $\endgroup$ – Szabolcs May 14 '18 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.