"Fossies" - the Fresh Open Source Software Archive 
Member "mapm_4.9.5a/MULTI_THREAD/m_apm_mt.h" (21 Feb 2010, 19447 Bytes) of package /linux/misc/old/mapm-4.9.5a.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "m_apm_mt.h" see the
Fossies "Dox" file reference documentation.
1
2 /*
3 * M_APM_MT - m_apm_mt.h
4 *
5 * Copyright (C) 2002 - 2007
6 * Martin Pfingstl (Martin.Pfingstl@epost.de)
7 * Michael C. Ring
8 *
9 * Modified from M_APM.H
10 *
11 * Permission to use, copy, and distribute this software and its
12 * documentation for any purpose with or without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and
14 * that both that copyright notice and this permission notice appear
15 * in supporting documentation.
16 *
17 * Permission to modify the software is granted. Permission to distribute
18 * the modified code is granted. Modifications are to be distributed by
19 * using the file 'license.txt' as a template to modify the file header.
20 * 'license.txt' is available in the official MAPM distribution.
21 *
22 * This software is provided "as is" without express or implied warranty.
23 */
24
25 /*
26 * This is an additional header file containing a thread safe C++ wrapper
27 *
28 * $Id: m_apm_mt.h,v 1.12 2007/12/03 02:22:11 mike Exp $
29 *
30 * $Log: m_apm_mt.h,v $
31 * Revision 1.12 2007/12/03 02:22:11 mike
32 * update license
33 * update version to 4.9.5
34 *
35 * Revision 1.11 2004/06/01 00:09:57 mike
36 * add MOD operator to C++ class
37 *
38 * Revision 1.10 2004/05/24 04:20:14 mike
39 * update version to 4.9.2
40 *
41 * Revision 1.9 2004/04/01 03:15:48 mike
42 * update version string
43 *
44 * Revision 1.8 2004/01/02 20:41:42 mike
45 * fix date on copyright
46 *
47 * Revision 1.7 2004/01/02 00:53:58 mike
48 * update version to 4.9
49 *
50 * Revision 1.6 2003/11/23 05:11:41 mike
51 * update version
52 *
53 * Revision 1.5 2003/07/21 21:01:59 mike
54 * update version to 4.8
55 *
56 * Revision 1.4 2003/05/14 21:28:02 mike
57 * update version string
58 *
59 * Revision 1.3 2003/05/07 22:51:59 mike
60 * add 2 new function prototypes and #defines for versions
61 *
62 * Revision 1.2 2002/11/10 22:40:54 mike
63 * add new ipow_nr function
64 *
65 * Revision 1.1 2002/06/13 20:39:06 mike
66 * Initial revision
67 */
68
69 #ifndef M__APMMT__INCLUDED
70 #define M__APMMT__INCLUDED
71
72 #ifdef __cplusplus
73 /* Comment this line out if you've compiled the library as C++. */
74 #define APM_CONVERT_FROM_C
75 #endif
76
77 #ifdef APM_CONVERT_FROM_C
78 extern "C" {
79 #endif
80
81 typedef unsigned char UCHAR;
82
83 typedef struct {
84 UCHAR *m_apm_data;
85 long m_apm_id;
86 int m_apm_refcount; /* <- used only by C++ MAPM class */
87 int m_apm_malloclength;
88 int m_apm_datalength;
89 int m_apm_exponent;
90 int m_apm_sign;
91 } M_APM_struct;
92
93 typedef M_APM_struct *M_APM;
94
95
96 #define MAPM_LIB_VERSION \
97 "MAPM Library Version 4.9.5 Copyright (C) 1999-2007, Michael C. Ring"
98 #define MAPM_LIB_SHORT_VERSION "4.9.5"
99
100
101 /*
102 * convienient predefined constants
103 */
104
105 extern M_APM MM_Zero;
106 extern M_APM MM_One;
107 extern M_APM MM_Two;
108 extern M_APM MM_Three;
109 extern M_APM MM_Four;
110 extern M_APM MM_Five;
111 extern M_APM MM_Ten;
112
113 extern M_APM MM_PI;
114 extern M_APM MM_HALF_PI;
115 extern M_APM MM_2_PI;
116 extern M_APM MM_E;
117
118 extern M_APM MM_LOG_E_BASE_10;
119 extern M_APM MM_LOG_10_BASE_E;
120 extern M_APM MM_LOG_2_BASE_E;
121 extern M_APM MM_LOG_3_BASE_E;
122
123
124 /*
125 * function prototypes
126 */
127
128
129 extern void m_apm_enter(void);
130 extern void m_apm_leave(void);
131 extern void m_apm_init_semaphore(void);
132 extern void m_apm_free_semaphore(void);
133
134 extern M_APM m_apm_init_mt(void);
135 extern void m_apm_free_mt(M_APM);
136 extern void m_apm_free_all_mem_mt(void);
137 extern void m_apm_trim_mem_usage_mt(void);
138 extern char *m_apm_lib_version_mt(char *);
139 extern char *m_apm_lib_short_version_mt(char *);
140
141 extern void m_apm_set_string_mt(M_APM, char *);
142 extern void m_apm_set_double_mt(M_APM, double);
143 extern void m_apm_set_long_mt(M_APM, long);
144
145 extern void m_apm_to_string_mt(char *, int, M_APM);
146 extern void m_apm_to_fixpt_string_mt(char *, int, M_APM);
147 extern void m_apm_to_fixpt_stringex_mt(char *, int, M_APM, char,
148 char, int);
149
150 extern char *m_apm_to_fixpt_stringexp_mt(int, M_APM, char, char, int);
151 extern void m_apm_to_integer_string_mt(char *, M_APM);
152
153 extern void m_apm_absolute_value_mt(M_APM, M_APM);
154 extern void m_apm_negate_mt(M_APM, M_APM);
155 extern void m_apm_copy_mt(M_APM, M_APM);
156 extern void m_apm_round_mt(M_APM, int, M_APM);
157 extern int m_apm_compare_mt(M_APM, M_APM);
158 extern int m_apm_sign_mt(M_APM);
159 extern int m_apm_exponent_mt(M_APM);
160 extern int m_apm_significant_digits_mt(M_APM);
161 extern int m_apm_is_integer_mt(M_APM);
162 extern int m_apm_is_even_mt(M_APM);
163 extern int m_apm_is_odd_mt(M_APM);
164
165 extern void m_apm_gcd_mt(M_APM, M_APM, M_APM);
166 extern void m_apm_lcm_mt(M_APM, M_APM, M_APM);
167
168 extern void m_apm_add_mt(M_APM, M_APM, M_APM);
169 extern void m_apm_subtract_mt(M_APM, M_APM, M_APM);
170 extern void m_apm_multiply_mt(M_APM, M_APM, M_APM);
171 extern void m_apm_divide_mt(M_APM, int, M_APM, M_APM);
172 extern void m_apm_integer_divide_mt(M_APM, M_APM, M_APM);
173 extern void m_apm_integer_div_rem_mt(M_APM, M_APM, M_APM, M_APM);
174 extern void m_apm_reciprocal_mt(M_APM, int, M_APM);
175 extern void m_apm_factorial_mt(M_APM, M_APM);
176 extern void m_apm_floor_mt(M_APM, M_APM);
177 extern void m_apm_ceil_mt(M_APM, M_APM);
178 extern void m_apm_get_random_mt(M_APM);
179 extern void m_apm_set_random_seed_mt(char *);
180
181 extern void m_apm_sqrt_mt(M_APM, int, M_APM);
182 extern void m_apm_cbrt_mt(M_APM, int, M_APM);
183 extern void m_apm_log_mt(M_APM, int, M_APM);
184 extern void m_apm_log10_mt(M_APM, int, M_APM);
185 extern void m_apm_exp_mt(M_APM, int, M_APM);
186 extern void m_apm_pow_mt(M_APM, int, M_APM, M_APM);
187 extern void m_apm_integer_pow_mt(M_APM, int, M_APM, int);
188 extern void m_apm_integer_pow_nr_mt(M_APM, M_APM, int);
189
190 extern void m_apm_sin_cos_mt(M_APM, M_APM, int, M_APM);
191 extern void m_apm_sin_mt(M_APM, int, M_APM);
192 extern void m_apm_cos_mt(M_APM, int, M_APM);
193 extern void m_apm_tan_mt(M_APM, int, M_APM);
194 extern void m_apm_arcsin_mt(M_APM, int, M_APM);
195 extern void m_apm_arccos_mt(M_APM, int, M_APM);
196 extern void m_apm_arctan_mt(M_APM, int, M_APM);
197 extern void m_apm_arctan2_mt(M_APM, int, M_APM, M_APM);
198
199 extern void m_apm_sinh_mt(M_APM, int, M_APM);
200 extern void m_apm_cosh_mt(M_APM, int, M_APM);
201 extern void m_apm_tanh_mt(M_APM, int, M_APM);
202 extern void m_apm_arcsinh_mt(M_APM, int, M_APM);
203 extern void m_apm_arccosh_mt(M_APM, int, M_APM);
204 extern void m_apm_arctanh_mt(M_APM, int, M_APM);
205
206 extern void m_apm_cpp_precision_mt(int); /* only for C++ wrapper */
207
208 /* more intuitive alternate names for the ARC functions ... */
209
210 #define m_apm_asin_mt m_apm_arcsin_mt
211 #define m_apm_acos_mt m_apm_arccos_mt
212 #define m_apm_atan_mt m_apm_arctan_mt
213 #define m_apm_atan2_mt m_apm_arctan2_mt
214
215 #define m_apm_asinh_mt m_apm_arcsinh_mt
216 #define m_apm_acosh_mt m_apm_arccosh_mt
217 #define m_apm_atanh_mt m_apm_arctanh_mt
218
219 #ifdef APM_CONVERT_FROM_C
220 } /* End extern "C" bracket */
221 #endif
222
223 #ifdef __cplusplus /*<- Hides the class below from C compilers */
224
225 /*
226 This class lets you use M_APM's a bit more intuitively with
227 C++'s operator and function overloading, constructors, etc.
228
229 Copied from M_APM.H, original from 3/24/2000 by Orion Sky Lawlor,
230 olawlor@acm.org
231 Class calls Multithreaded versions of functions (secured by a semaphore)
232 */
233
234
235 extern
236 #ifdef APM_CONVERT_FROM_C
237 "C"
238 #endif
239 int MM_cpp_min_precision;
240
241
242 class MAPMMT {
243 protected:
244
245 /*
246 The M_APM structure here is implemented as a reference-
247 counted, copy-on-write data structure-- this makes copies
248 very fast, but that's why it's so ugly. A MAPMMT object is
249 basically just a wrapper around a (possibly shared)
250 M_APM_struct myVal.
251
252 Note: Only public functions need to be secured for multi threading.
253 All private functions can only be called from public functions
254 and thus thread safety is ensured.
255 */
256
257 public:
258 M_APM myVal; /* My M_APM structure */
259 protected:
260 void create(void) {myVal=makeNew();}
261 void destroy(void) {unref(myVal);myVal=NULL;}
262 void copyFrom(M_APM Nval)
263 {
264 M_APM oldVal=myVal;
265 myVal=Nval;
266 ref(myVal);
267 unref(oldVal);
268 }
269 static M_APM makeNew(void)
270 {
271 M_APM val=m_apm_init_mt();
272 /* refcount initialized to 1 by 'm_apm_init' */
273 return val;
274 }
275 static void ref(M_APM val)
276 {
277 val->m_apm_refcount++;
278 }
279 static void unref(M_APM val)
280 {
281 val->m_apm_refcount--;
282 if (val->m_apm_refcount==0)
283 m_apm_free_mt(val);
284 }
285
286 /* This routine is called to get a private (mutable)
287 copy of our current value. */
288 M_APM val(void)
289 {
290 if (myVal->m_apm_refcount==1)
291 /* Return my private myVal */
292 return myVal;
293
294 /* Otherwise, our copy of myVal is shared--
295 we need to make a new private copy.
296 */
297 M_APM oldVal=myVal;
298 myVal=makeNew();
299 m_apm_copy_mt(myVal,oldVal);
300 unref(oldVal);
301 return myVal;
302 }
303
304 /*BAD: C M_APM routines doesn't use "const" where they should--
305 hence we have to cast to a non-const type here (FIX THIS!).
306
307 (in due time.... MCR)
308 */
309 M_APM cval(void) const
310 {
311 return (M_APM)myVal;
312 }
313 /* This is the default number of digits to use for
314 1-ary functions like sin, cos, tan, etc.
315 It's the larger of my digits and cpp_min_precision.
316 */
317 int myDigits(void) const
318 {
319 int maxd=m_apm_significant_digits_mt(cval());
320 if (maxd<MM_cpp_min_precision) maxd=MM_cpp_min_precision;
321 return maxd;
322 }
323 /* This is the default number of digits to use for
324 2-ary functions like divide, atan2, etc.
325 It's the larger of my digits, his digits, and cpp_min_precision.
326 */
327 int digits(const MAPMMT &otherVal) const
328 {
329 int maxd=myDigits();
330 int his=m_apm_significant_digits_mt(otherVal.cval());
331 if (maxd<his) maxd=his;
332 return maxd;
333 }
334 public:
335 /* Constructors: */
336 MAPMMT(void) /* Default constructor (takes no value) */
337 {m_apm_enter();create();m_apm_leave();}
338 MAPMMT(const MAPMMT &m) /* Copy constructor */
339 {m_apm_enter();myVal=(M_APM)m.cval();ref(myVal);m_apm_leave();}
340 MAPMMT(M_APM m) /* M_APM constructor (refcount starts at one) */
341 {m_apm_enter();myVal=(M_APM)m;ref(myVal);m_apm_leave();}
342 MAPMMT(const char *s) /* Constructor from string */
343 {m_apm_enter();create();m_apm_set_string_mt(val(),(char *)s);m_apm_leave();}
344 MAPMMT(double d) /* Constructor from double-precision float */
345 {m_apm_enter();create();m_apm_set_double_mt(val(),d);m_apm_leave();}
346 MAPMMT(int l) /* Constructor from int */
347 {m_apm_enter();create();m_apm_set_long_mt(val(),l);m_apm_leave();}
348 MAPMMT(long l) /* Constructor from long int */
349 {m_apm_enter();create();m_apm_set_long_mt(val(),l);m_apm_leave();}
350 /* Destructor */
351 ~MAPMMT() {m_apm_enter();destroy();m_apm_leave();}
352
353 /* Extracting string descriptions: */
354 void toString(char *dest,int decimalPlaces) const
355 {m_apm_to_string_mt(dest,decimalPlaces,cval());}
356 void toFixPtString(char *dest,int decimalPlaces) const
357 {m_apm_to_fixpt_string_mt(dest,decimalPlaces,cval());}
358 void toFixPtStringEx(char *dest,int dp,char a,char b,int c) const
359 {m_apm_to_fixpt_stringex_mt(dest,dp,cval(),a,b,c);}
360 char *toFixPtStringExp(int dp,char a,char b,int c) const
361 {return(m_apm_to_fixpt_stringexp_mt(dp,cval(),a,b,c));}
362 void toIntegerString(char *dest) const
363 {m_apm_to_integer_string_mt(dest,cval());}
364
365 /* Basic operators: */
366 MAPMMT &operator=(const MAPMMT &m) /* Assigment operator */
367 {m_apm_enter();copyFrom((M_APM)m.cval());m_apm_leave();return *this;}
368 MAPMMT &operator=(const char *s) /* Assigment operator */
369 {m_apm_set_string_mt(val(),(char *)s);return *this;}
370 MAPMMT &operator=(double d) /* Assigment operator */
371 {m_apm_set_double_mt(val(),d);return *this;}
372 MAPMMT &operator=(int l) /* Assigment operator */
373 {m_apm_set_long_mt(val(),l);return *this;}
374 MAPMMT &operator=(long l) /* Assigment operator */
375 {m_apm_set_long_mt(val(),l);return *this;}
376 MAPMMT operator++() /* Prefix increment operator */
377 {m_apm_enter();*this = *this+MM_One;m_apm_leave();return *this;}
378 MAPMMT operator--() /* Prefix decrement operator */
379 {m_apm_enter();*this = *this-MM_One;m_apm_leave();return *this;}
380 const MAPMMT operator++(int) /* Postfix increment operator */
381 {
382 m_apm_enter();
383 MAPMMT old = *this;
384 ++(*this); /* Call prefix increment */
385 m_apm_leave();
386 return old;
387 }
388 const MAPMMT operator--(int) /* Postfix decrement operator */
389 {
390 m_apm_enter();
391 MAPMMT old = *this;
392 --(*this); /* Call prefix decrement */
393 m_apm_leave();
394 return old;
395 }
396
397 /* Comparison operators */
398 int operator==(const MAPMMT &m) const /* Equality operator */
399 {return m_apm_compare_mt(cval(),m.cval())==0;}
400 int operator!=(const MAPMMT &m) const /* Inequality operator */
401 {return m_apm_compare_mt(cval(),m.cval())!=0;}
402 int operator<(const MAPMMT &m) const
403 {return m_apm_compare_mt(cval(),m.cval())<0;}
404 int operator<=(const MAPMMT &m) const
405 {return m_apm_compare_mt(cval(),m.cval())<=0;}
406 int operator>(const MAPMMT &m) const
407 {return m_apm_compare_mt(cval(),m.cval())>0;}
408 int operator>=(const MAPMMT &m) const
409 {return m_apm_compare_mt(cval(),m.cval())>=0;}
410
411 /* Basic arithmetic operators */
412 friend MAPMMT operator+(const MAPMMT &a,const MAPMMT &b)
413 {MAPMMT ret;m_apm_add_mt(ret.val(),a.cval(),b.cval());return ret;}
414 friend MAPMMT operator-(const MAPMMT &a,const MAPMMT &b)
415 {MAPMMT ret;m_apm_subtract_mt(ret.val(),a.cval(),b.cval());return ret;}
416 friend MAPMMT operator*(const MAPMMT &a,const MAPMMT &b)
417 {MAPMMT ret;m_apm_multiply_mt(ret.val(),a.cval(),b.cval());return ret;}
418 friend MAPMMT operator%(const MAPMMT &a,const MAPMMT &b)
419 {MAPMMT quot,ret;m_apm_integer_div_rem_mt(quot.val(),ret.val(),
420 a.cval(),b.cval());return ret;}
421
422 /* Default division keeps larger of cpp_min_precision, numerator
423 digits of precision, or denominator digits of precision. */
424 friend MAPMMT operator/(const MAPMMT &a,const MAPMMT &b)
425 {return a.divide(b,a.digits(b));}
426
427 MAPMMT divide(const MAPMMT &m,int toDigits) const
428 {MAPMMT ret;m_apm_divide_mt(ret.val(),toDigits,cval(), m.cval());return ret;}
429 MAPMMT divide(const MAPMMT &m) const {return divide(m,digits(m));}
430
431 /* Assignment arithmetic operators */
432 MAPMMT &operator+=(const MAPMMT &m) {*this = *this+m;return *this;}
433 MAPMMT &operator-=(const MAPMMT &m) {*this = *this-m;return *this;}
434 MAPMMT &operator*=(const MAPMMT &m) {*this = *this*m;return *this;}
435 MAPMMT &operator/=(const MAPMMT &m) {*this = *this/m;return *this;}
436 MAPMMT &operator%=(const MAPMMT &m) {*this = *this%m;return *this;}
437
438 /* Extracting/setting simple information: */
439 int sign(void) const
440 {return m_apm_sign_mt(cval());}
441 int exponent(void) const
442 {return m_apm_exponent_mt(cval());}
443 int significant_digits(void) const
444 {return m_apm_significant_digits_mt(cval());}
445 int is_integer(void) const
446 {return m_apm_is_integer_mt(cval());}
447 int is_even(void) const
448 {return m_apm_is_even_mt(cval());}
449 int is_odd(void) const
450 {return m_apm_is_odd_mt(cval());}
451
452 /* Functions: */
453 MAPMMT abs(void) const
454 {MAPMMT ret;m_apm_absolute_value_mt(ret.val(),cval());return ret;}
455 MAPMMT neg(void) const
456 {MAPMMT ret;m_apm_negate_mt(ret.val(),cval());return ret;}
457 MAPMMT round(int toDigits) const
458 {MAPMMT ret;m_apm_round_mt(ret.val(),toDigits,cval());return ret;}
459 MAPMMT operator-(void) const {return neg();}
460
461 /* I got tired of typing the various declarations for a simple
462 1-ary real-to-real function on MAPMMT's; hence this define:
463 The digits-free versions return my digits of precision or
464 cpp_min_precision, whichever is bigger.
465 */
466
467 #define MAPMMT_1aryFunc(func) \
468 MAPMMT func(int toDigits) const\
469 {MAPMMT ret;m_apm_##func##_mt(ret.val(),toDigits,cval());return ret;}\
470 MAPMMT func(void) const {return func(myDigits());}
471
472 MAPMMT_1aryFunc(sqrt)
473 MAPMMT_1aryFunc(cbrt)
474 MAPMMT_1aryFunc(log)
475 MAPMMT_1aryFunc(exp)
476 MAPMMT_1aryFunc(log10)
477 MAPMMT_1aryFunc(sin)
478 MAPMMT_1aryFunc(asin)
479 MAPMMT_1aryFunc(cos)
480 MAPMMT_1aryFunc(acos)
481 MAPMMT_1aryFunc(tan)
482 MAPMMT_1aryFunc(atan)
483 MAPMMT_1aryFunc(sinh)
484 MAPMMT_1aryFunc(asinh)
485 MAPMMT_1aryFunc(cosh)
486 MAPMMT_1aryFunc(acosh)
487 MAPMMT_1aryFunc(tanh)
488 MAPMMT_1aryFunc(atanh)
489 #undef MAPMMT_1aryFunc
490
491 void sincos(MAPMMT &sinR,MAPMMT &cosR,int toDigits)
492 {m_apm_sin_cos_mt(sinR.val(),cosR.val(),toDigits,cval());}
493 void sincos(MAPMMT &sinR,MAPMMT &cosR)
494 {sincos(sinR,cosR,myDigits());}
495 MAPMMT pow(const MAPMMT &m,int toDigits) const
496 {MAPMMT ret;m_apm_pow_mt(ret.val(),toDigits,cval(),
497 m.cval());return ret;}
498 MAPMMT pow(const MAPMMT &m) const {return pow(m,digits(m));}
499 MAPMMT atan2(const MAPMMT &x,int toDigits) const
500 {MAPMMT ret;m_apm_arctan2_mt(ret.val(),toDigits,cval(),
501 x.cval());return ret;}
502 MAPMMT atan2(const MAPMMT &x) const
503 {return atan2(x,digits(x));}
504
505 MAPMMT gcd(const MAPMMT &m) const
506 {MAPMMT ret;m_apm_gcd_mt(ret.val(),cval(),m.cval());return ret;}
507
508 MAPMMT lcm(const MAPMMT &m) const
509 {MAPMMT ret;m_apm_lcm_mt(ret.val(),cval(),m.cval());return ret;}
510
511 static MAPMMT random(void)
512 {MAPMMT ret;m_apm_get_random_mt(ret.val());return ret;}
513
514 MAPMMT floor(void) const
515 {MAPMMT ret;m_apm_floor_mt(ret.val(),cval());return ret;}
516 MAPMMT ceil(void) const
517 {MAPMMT ret;m_apm_ceil_mt(ret.val(),cval());return ret;}
518
519 /* Functions defined only on integers: */
520 MAPMMT factorial(void) const
521 {MAPMMT ret;m_apm_factorial_mt(ret.val(),cval());return ret;}
522 MAPMMT ipow_nr(int p) const
523 {MAPMMT ret;m_apm_integer_pow_nr_mt(ret.val(),
524 cval(),p);return ret;}
525 MAPMMT ipow(int p,int toDigits) const
526 {MAPMMT ret;m_apm_integer_pow_mt(ret.val(),
527 toDigits,cval(),p);return ret;}
528 MAPMMT ipow(int p) const
529 {return ipow(p,myDigits());}
530
531 MAPMMT integer_divide(const MAPMMT &denom) const
532 {MAPMMT ret;m_apm_integer_divide_mt(ret.val(),cval(),
533 denom.cval());return ret;}
534 void integer_div_rem(const MAPMMT &denom,MAPMMT ",MAPMMT &rem) const
535 {m_apm_integer_div_rem_mt(quot.val(),rem.val(),cval(),
536 denom.cval());}
537 MAPMMT div(const MAPMMT &denom) const {return integer_divide(denom);}
538 MAPMMT rem(const MAPMMT &denom) const {MAPMMT ret,ignored;
539 integer_div_rem(denom,ignored,ret);return ret;}
540 };
541
542 /* math.h-style functions: */
543
544 inline MAPMMT fabs(const MAPMMT &m) {return m.abs();}
545 inline MAPMMT factorial(const MAPMMT &m) {return m.factorial();}
546 inline MAPMMT floor(const MAPMMT &m) {return m.floor();}
547 inline MAPMMT ceil(const MAPMMT &m) {return m.ceil();}
548 inline MAPMMT get_random(void) {return MAPMMT::random();}
549
550 /* I got tired of typing the various declarations for a simple
551 1-ary real-to-real function on MAPMMT's; hence this define:
552 */
553 #define MAPMMT_1aryFunc(func) \
554 inline MAPMMT func(const MAPMMT &m) {return m.func();} \
555 inline MAPMMT func(const MAPMMT &m,int toDigits) {return m.func(toDigits);}
556
557 /* Define a big block of simple functions: */
558 MAPMMT_1aryFunc(sqrt)
559 MAPMMT_1aryFunc(cbrt)
560 MAPMMT_1aryFunc(log)
561 MAPMMT_1aryFunc(exp)
562 MAPMMT_1aryFunc(log10)
563 MAPMMT_1aryFunc(sin)
564 MAPMMT_1aryFunc(asin)
565 MAPMMT_1aryFunc(cos)
566 MAPMMT_1aryFunc(acos)
567 MAPMMT_1aryFunc(tan)
568 MAPMMT_1aryFunc(atan)
569 MAPMMT_1aryFunc(sinh)
570 MAPMMT_1aryFunc(asinh)
571 MAPMMT_1aryFunc(cosh)
572 MAPMMT_1aryFunc(acosh)
573 MAPMMT_1aryFunc(tanh)
574 MAPMMT_1aryFunc(atanh)
575 #undef MAPMMT_1aryFunc
576
577 /* Computes x to the power y */
578 inline MAPMMT pow(const MAPMMT &x,const MAPMMT &y,int toDigits)
579 {return x.pow(y,toDigits);}
580 inline MAPMMT pow(const MAPMMT &x,const MAPMMT &y)
581 {return x.pow(y);}
582 inline MAPMMT atan2(const MAPMMT &y,const MAPMMT &x,int toDigits)
583 {return y.atan2(x,toDigits);}
584 inline MAPMMT atan2(const MAPMMT &y,const MAPMMT &x)
585 {return y.atan2(x);}
586 inline MAPMMT gcd(const MAPMMT &u,const MAPMMT &v)
587 {return u.gcd(v);}
588 inline MAPMMT lcm(const MAPMMT &u,const MAPMMT &v)
589 {return u.lcm(v);}
590 #endif
591 #endif
592