"Fossies" - the Fresh Open Source Software Archive 
Member "mapm_4.9.5a/DOCS/cpp_function.ref" (21 Feb 2010, 7730 Bytes) of package /linux/misc/old/mapm-4.9.5a.tar.gz:
As a special service "Fossies" has tried to format the requested text file into HTML format (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1
2 -----------------------------------------------------------------------------
3 MAPM C++ Wrapper Function Descriptions June 10, 2004
4 By: Orion Sky Lawlor
5 Ongoing Maintenance by Michael Ring
6 -----------------------------------------------------------------------------
7
8 See the file 'cpp_demo.cpp.' This is a demo program which calls all possible
9 C++ functions defined in the library. This should be a good starting point
10 in your C++ applications.
11
12 -----------------------------------------------------------------------------
13
14 -------- CREATION / ASSIGNMENT: --------
15
16 A MAPM object represents a single decimal number. You can
17 create a MAPM uninitialized, from a string (see m_apm_set_string),
18 from an integral type, or from a float or double.
19 e.g.:
20 MAPM a; //a is uninitialized (value is undefined)
21 MAPM b="4.5e12"; //b is 4.5 trillion
22 MAPM c=3; //c is now three
23 MAPM d=6.1; //d is now six point one
24 MAPM e=c; //e is now three
25
26 You can also assign to a MAPM from any of these types, e.g.:
27 d="-2e-24"; // d is now minus two trillion-trillionths.
28
29 You can also allocate arrays of MAPM objects, e.g.:
30 MAPM arr[17];
31 MAPM *parr=new MAPM[17];
32
33 Arrays are always created uninitialized.
34
35
36 ------- ARITHMETIC OPERATORS: -------
37
38 These operators are defined for MAPM objects:
39 arithmetic: +, -, *, /, %
40 assigment-arithmetic: +=, -=, *=, /=, %=
41 comparison operators: ==, !=, <, <=, >, >=
42 prefix: ++, --
43 postfix: ++, --
44 unary negation: -
45
46 These operators have the same precedence, associativity,
47 and semantics as the corresponding C operators. The
48 operators ||, &&, |, &, ~, ^, (), and ! are not defined.
49
50 The increment/decrement operators are defined even for non-integer
51 MAPM numbers, they simply add or subtract one from the value.
52
53 The division operator uses the standard precision rule (below);
54 all other operators maintain all digits.
55
56
57 -------- LIBRARY ROUTINES: ------
58
59 All routines below are available with or without specified precision,
60 and in member and "math.h" form. For example, for a one-input
61 function foo(x), you can call foo with any of the forms:
62 MAPM x;
63 x.foo(); // Member function form
64 x.foo(n); // with n digits of precision
65 foo(x); // "math.h" form
66 foo(x,n); // with n digits of precision
67
68 For a two-input function bar(x,y), the forms are:
69 MAPM x,y;
70 x.bar(y); // Member function form
71 x.bar(y,n); // with n digits of precision
72 bar(x,y); // "math.h" form
73 bar(x,y,n); // with n digits of precision
74
75 See the standard precision rules below if no precision is specified.
76
77 The library functions are:
78
79 z=sqrt(x) -- Return the square root of x, so x==z*z
80 z=cbrt(x) -- Return the cube root of x, so x==z*z*z
81 z=log(x) -- Return the base-e logarithm of x, so x==exp(z)
82 z=log10(x) -- Return the base-10 logarithm of x, so x==pow(10,z)
83 z=exp(x) -- Return e raised to the power x, so x==log(z)
84 pow(x,y) -- Return x raised to the power y
85 sin(x) -- Return the sine of x, with x in radians
86 cos(x) -- Return the cosine of x, with x in radians
87 tan(x) -- Return the tangent of x, with x in radians
88 asin(x) -- Return the inverse sine of x, in radians
89 acos(x) -- Return the inverse cosine of x, in radians
90 atan(x) -- Return the inverse tangent of x, in radians
91 atan2(y,x) -- Return the 4 quadrant inverse tangent of y/x
92 sinh(x) -- Return the hyperbolic sine of x
93 cosh(x) -- Return the hyperbolic cosine of x
94 tanh(x) -- Return the hyperbolic tangent of x
95 asinh(x) -- Return the inverse hyperbolic sine of x
96 acosh(x) -- Return the inverse hyperbolic cosine of x
97 atanh(x) -- Return the inverse hyperbolic tangent of x
98
99 Each function above is available in all four forms.
100
101 Additional math.h type functions:
102
103 get_random() -- Return a "random" MAPM on [0,1). see m_apm_get_random
104 factorial(x) -- Return the factorial of x. see m_apm_factorial
105 fabs(x) -- Return the absolute value of x.
106 floor(x) -- Return the floor of x.
107 ceil(x) -- Return the ceil of x.
108 gcd(x,y) -- Return the GCD (greatest common divisor) of x, y.
109 lcm(x,y) -- Return the LCM (least common multiple) of x, y.
110
111
112 ---------- STANDARD PRECISION RULES: ---------
113
114 Addition, subtraction, and multiplication maintain ALL significant
115 digits.
116
117 All other operations (divide, sin, etc) can take a number of
118 digits n. In this case, the result will have an n-digit mantissa.
119 If no precision is specified, they use the following rules:
120
121 1) if the operation uses only one input value [y = sin(x)], the
122 result 'y' will be the same precision as 'x' or the default
123 precision, whichever is larger.
124
125 2) if the operation uses two input values [z = atan2(y,x)], the
126 result 'z' will be the digits of 'x', digits of 'y', or the
127 default precision, whichever is larger.
128
129 The default precision starts at 30 digits. You can change the
130 precision at any time with the function 'm_apm_cpp_precision'
131 (see function.ref).
132
133 e.g.:
134 m_apm_cpp_precision(80);
135
136 will result in all operations being accurate to a minimum of 80 significant
137 digits. If any operand contains more than the minimum number of digits, then
138 the result will contain the max number of digits of the operands.
139
140
141 -------- UTILITY: --------
142
143 m.sign() extracts the sign of a MAPM m, as
144 -1 : m < 0
145 0 : m = 0
146 1 : m > 0
147
148 m.exponent() returns the exponent (power of 10) of a MAPM m.
149
150 m.significant_digits() returns the total number of decimal digits
151 in the mantissa of a MAPM m.
152
153 m.is_integer() returns 1 (TRUE) if the MAPM number m is an integer
154 value, 0 (FALSE) if not.
155
156 m.is_even() returns 1 (TRUE) if the MAPM number m is an EVEN integer
157 value, 0 (FALSE) if not.
158
159 m.is_odd() returns 1 (TRUE) if the MAPM number m is an ODD integer
160 value, 0 (FALSE) if not.
161
162 m.abs() and abs(m) return the absolute value of a MAPM m, which
163 remains unchanged.
164
165 m.neg() is a faster version of the expression "-1*m".
166
167 m.round(n) returns a version of a MAPM m rounded to n decimal places.
168 m remains unchanged.
169
170 MAPM::random() returns a "random" MAPM on [0,1). See also 'get_random'
171 above.
172
173 m.ipow(k) returns m to the integer power k with the standard precision.
174 m.ipow(k,n) returns m to the integer power k with n digits of precision.
175
176 m.ipow_nr(k) returns m to the integer power k with ALL precision (No rounding
177 takes place; more appropriate for integer only applications).
178 'k' must be >= zero.
179
180 m.div(d) returns the largest MAPM integer not greater than the
181 quotient m/d. (MAPM m, d, return value;)
182
183 m.rem(d) returns the remainder after dividing m by d. (MAPM m, d,
184 return value;)
185
186 m.integer_div_rem(d,q,r) sets the MAPM q and r to m.div(d) and
187 m.rem(d) respectively. (but faster than calling div, rem separately).
188
189 m.sincos(s,c) sets the MAPM s and c to m.sin() and m.cos()
190 respectively. (but faster than calling them separately).
191 m.sincos(s,c,n) is as above, but keeps exactly n digits of precision.
192
193
194 -------- OUTPUT: ----------
195
196 You can print a MAPM object by first converting it to a string with
197
198 1) toString (see m_apm_to_string)
199 2) toFixPtString (see m_apm_to_fixpt_string)
200 3) toFixPtStringEx (see m_apm_to_fixpt_stringex)
201 4) toFixPtStringExp (see m_apm_to_fixpt_stringexp)
202 5) toIntegerString (see m_apm_to_integer_string)
203
204 e.g.:
205 MAPM a=Factorial(17);
206 char obuf[1000];
207 a.toIntegerString(obuf);
208 cout<<obuf;
209
210 Of course, obuf must be long enough to contain the digits of 'a'.
211
212 If the required string length of the result is not known, use the
213 'significant_digits' utility operator from above to determine how
214 many bytes (+ some padding for the possible sign & exponent) to
215 malloc/new.
216