Listing 1: Using the C++ wrapper class with MAPM


//    
//    Example MAPM C++ code with output.
//
//    Note the use of literal character strings as constants.
//
//    This allows the user to specify constants that cannot be
//    represented by a standard C datatype, such as a number with 
//    200 digits or a number with a very large or small exponent 
//    (i.e., 6.21E-3714).
//

char  outbuf[256];
MAPM  u, v, w, x, y, z;         // arbitrary precision datatype

m_apm_cpp_precision(50);        // set MINIMUM precision level
                                // for all calculations

x = 9.34231;
y = -21;
z = "-8.982349249829824921479824924792347921E-17";

w = (82.30421 + sin(x / "21.11")
              / exp(y * 0.0726426)) * "4.32917E-2" / z;
v = "3.742416" * log(-w);
u = sqrt(v) + cbrt(v);

x.toString(outbuf, 50);   printf("x = [%s] \n",outbuf); 
y.toString(outbuf, 50);   printf("y = [%s] \n",outbuf); 
z.toString(outbuf, 50);   printf("z = [%s] \n",outbuf); 
w.toString(outbuf, 50);   printf("w = [%s] \n",outbuf); 
v.toString(outbuf, 50);   printf("v = [%s] \n",outbuf); 
u.toString(outbuf, 50);   printf("u = [%s] \n",outbuf); 

//    
//    end sample code 
//    


/*
Output from above code :

x = [9.34231000000000000000000000000000000000000000000000E+0] 
y = [-2.10000000000000000000000000000000000000000000000000E+1] 
z = [-8.98234924982982492147982492479234792100000000000000E-17] 
w = [-4.06165846135776503301770738763183914451375637893923E+16] 
v = [1.43121038693447060414449698088102300924570797933606E+2] 
u = [1.71941170788317776083850581271655444461072359345223E+1] 
*/

End of Listing 

The views and opinions expressed in this page are strictly those of the page author.
The contents of this page have not been reviewed or approved by the University of Minnesota.