Both FortranAssign and CAssign convert to the full set of compiled language functions according to the American National Standards Institute guidelines. Some examples of translating to compiled language intrinsics are given in this section. CAssign and FortranAssign automatically test for the presence of non-standard ANSI C and FORTRAN functions. An appropriate warning message is issued the first time a function which does not conform to the standard is encountered.
In[4]:= FortranAssign[Sin[f[x]]+f[x]] AssignFunction::undef: Expression contains the function f which is not part of the ANSI FORTRAN standard. Out[4]//OutputForm= sin(f(x))+f(x)Only generic functions are used. These are functions which are not restricted by their arguments. For example, sin is generic whereas dsin is not, since it only accepts double precision arguments.
However, in some cases it is desirable to mix Mathematica with target language code. The ANSI test function also knows about type-specific variants of functions, which are assumed to be in lower case form.
In[5]:= FortranAssign[ Cos[x]+dsin[y] ] Out[5]//OutputForm= cos(x)+dsin(y)Examples in C include functions such as fabs and fmod which are real argument versions of abs and mod.
This concept can be taken further to produce code fragments. This example uses the FORTRAN function dim(x,y), which returns the maximum of x-y and 0. First the ANSI compatibility message is suppressed because programming language constructs are not implemented in the test.
In[6]:= Off[AssignFunction::undef]; In[7]:= FortranAssign[ if[dim[x,y]<10,y,x] ] Out[7]//OutputForm= if(dim(x,y).lt.1.d1,y,x)The user should take care when using Mathematica constructs with the Hold attribute.