|
AndroMeta
2.0.0
|
00001 /* 00002 * Copyright 2009-2012 AndroMeta LLC. All rights reserved. 00003 * 00004 * AndroMeta LLC retains all intellectual property and proprietary 00005 * rights to this software and related documentation and any modifications 00006 * thereto. Any use, reproduction, disclosure, or distribution of this 00007 * software and related documentation without an express license agreement 00008 * from AndroMeta LLC is strictly prohibited. 00009 * 00010 */ 00011 00018 #ifndef ANDROMETA_M_LIB_H 00019 #define ANDROMETA_M_LIB_H 00020 00021 #include <cmath> 00022 00023 #include <AndroMeta/MLibBase.h> 00024 #include <AndroMeta/MNode.h> 00025 #include <AndroMeta/MVar.h> 00026 #include <AndroMeta/MObject.h> 00027 #include <AndroMeta/MMath.h> 00028 #include <AndroMeta/MProgram.h> 00029 #include <AndroMeta/MTime.h> 00030 00031 namespace Meta{ 00032 00037 class MLib : public MLibBase{ 00038 public: 00039 00043 MLib(); 00044 00048 virtual ~MLib(); 00049 00053 static mvar toVar(mnode n, bool codeData=false); 00054 00058 static mvar fromStr(const mstr& str, bool literal=true, bool exact=false){ 00059 return mvar::fromStr(str, literal, exact); 00060 } 00061 00067 static void srand(uint64_t seed); 00068 00069 // ---- probability distributions 00070 00074 static double uniform(); 00075 00079 static double uniform(double a, double b); 00080 00084 static double exponential(double x); 00085 00089 static double normal(double m, double s); 00090 00094 static double erlang(double n, double x); 00095 00099 static double pareto(double k, double a); 00100 00104 static double lognormal(double a, double b); 00105 00109 static double chisquare(double n); 00110 00114 static long bernoulli(double p); 00115 00119 static long equilikely(long a, long b); 00120 00124 static long binomial(long n, double p); 00125 00129 static long geometric(double p); 00130 00134 static long bpascal(long n, double p); 00135 00139 static long poisson(double m); 00140 00144 static const mvar& choice(const mvar& seq); 00145 00149 static mvec randomSequence(long a, long b); 00150 00156 static mvar mixedDistribution(const mvar& v); 00157 00158 // ---- math functions 00159 00163 static mvar degrees(const mvar& d){ 00164 return MMath::degrees(d); 00165 } 00166 00170 static double pi(){ 00171 return M_PI; 00172 } 00173 00177 static double sqrt(double v){ 00178 return std::sqrt(v); 00179 } 00180 00184 static double pow(double v, double exponent){ 00185 return std::pow(v, exponent); 00186 } 00187 00191 static double abs(double v){ 00192 return std::fabs(v); 00193 } 00194 00198 static double log10(double v){ 00199 return std::log10(v); 00200 } 00201 00205 static double cos(double v){ 00206 return std::cos(v); 00207 } 00208 00212 static double acos(double v){ 00213 return std::acos(v); 00214 } 00215 00219 static double cosh(double v){ 00220 return std::cosh(v); 00221 } 00222 00226 static double sin(double v){ 00227 return std::sin(v); 00228 } 00229 00233 static double asin(double v){ 00234 return std::asin(v); 00235 } 00236 00240 static double sinh(double v){ 00241 return std::sinh(v); 00242 } 00243 00247 static double tan(double v){ 00248 return std::tan(v); 00249 } 00250 00254 static double atan(double v){ 00255 return std::atan(v); 00256 } 00257 00261 static double atan2(double y, double x){ 00262 return std::atan2(y, x); 00263 } 00264 00268 static double tanh(double v){ 00269 return std::tanh(v); 00270 } 00271 00275 static double inf(){ 00276 return mvar::inf(); 00277 } 00278 00282 static double negInf(){ 00283 return mvar::negInf(); 00284 } 00285 00289 static double floor(double v){ 00290 return std::floor(v); 00291 } 00292 00296 static double ceil(double v){ 00297 return MLib::ceil(v); 00298 } 00299 00303 static double round(double v, double precision=1){ 00304 return MMath::round(v, precision); 00305 } 00306 00310 static bool nearInteger(double v, mvar& n){ 00311 return MMath::nearInteger(v, n); 00312 } 00313 00317 static double distance(const mvar& u, const mvar& v){ 00318 return MMath::fastDistance(u, v); 00319 } 00320 00324 static mvar scaleVector(const mvar& u, double magnitude){ 00325 return MMath::scaleVector(u, magnitude); 00326 } 00327 00331 static mvec vectorRange(const mvar& b){ 00332 return MMath::vectorRange(b); 00333 } 00334 00338 static mvec vectorRange(const mvar& a, const mvar& b){ 00339 return MMath::vectorRange(a, b); 00340 } 00341 00345 static mvec vectorRange(const mvar& a, const mvar& b, const mvar& inc){ 00346 return MMath::vectorRange(a, b, inc); 00347 } 00348 00352 static mlist listRange(const mvar& b){ 00353 return MMath::listRange(b); 00354 } 00355 00359 static mlist listRange(const mvar& a, const mvar& b){ 00360 return MMath::listRange(a, b); 00361 } 00362 00366 static mlist listRange(const mvar& a, const mvar& b, const mvar& inc){ 00367 return MMath::listRange(a, b, inc); 00368 } 00369 00373 static mvar clamp(const mvar& v, const mvar& min, const mvar& max){ 00374 return MMath::clamp(v, min, max); 00375 } 00376 00377 // ---- miscellaneous functions 00378 00382 static void sleep(double secs){ 00383 mtime::sleep(secs); 00384 } 00385 00389 static void print(const mstr& str); 00390 00394 static mstr repeatString(const mstr& str, int n); 00395 00402 static mvar mergeSymbolicMaps(const mvar& m1, const mvar& m2); 00403 00407 static bool hasArg(const mvar& key){ 00408 return MProgram::hasArg(key); 00409 } 00410 00414 static mvar args(){ 00415 return MProgram::args(); 00416 } 00417 00421 static void setArgs(const mvar& args){ 00422 MProgram::setArgs(args); 00423 } 00424 00428 static mvar arg(const mvar& key){ 00429 return MProgram::arg(key); 00430 } 00431 00435 static mvar arg(const mvar& key, const mvar& def){ 00436 return MProgram::arg(key, def); 00437 } 00438 00442 static void setArg(const mvar& key, const mvar& value){ 00443 MProgram::setArg(key, value); 00444 } 00445 00449 static void argDefault(const mvar& key, const mvar& value){ 00450 MProgram::argDefault(key, value); 00451 } 00452 00456 static double systemTime(){ 00457 return mtime::now(); 00458 } 00459 00463 static mstr formatTime(double t, const mstr& format){ 00464 mtime time(t, true); 00465 return time.toStr(format); 00466 } 00467 00471 static void setDefaultPrecision(size_t bits){ 00472 MReal::setDefaultPrecision(bits); 00473 } 00474 00478 static mstr formatTime(double t){ 00479 mtime time(t, true); 00480 return time.toStr(); 00481 } 00482 00486 static mvec crossProduct(const mvec& u, const mvec& v); 00487 00492 static mvar dotProduct(const mvec& u, const mvec& v); 00493 00497 virtual mnode process(mnode n, uint32_t flags=0); 00498 00499 private: 00500 bool restricted_; 00501 00502 MLib& operator=(const MLib&); 00503 MLib(const MLib&); 00504 }; 00505 00506 namespace MFunc{ 00507 inline mvar toVar(mnode n, bool codeData=false){ 00508 return MLib::toVar(n, codeData); 00509 } 00510 00511 inline mvar fromStr(const mstr& str, bool literal=true, bool exact=false){ 00512 return MLib::fromStr(str, literal, exact); 00513 } 00514 00515 inline void srand(uint64_t seed){ 00516 return MLib::srand(seed); 00517 } 00518 00519 inline double uniform(){ 00520 return MLib::uniform(); 00521 } 00522 00523 inline double uniform(double a, double b){ 00524 return MLib::uniform(a, b); 00525 } 00526 00527 inline double exponential(double x){ 00528 return MLib::exponential(x); 00529 } 00530 00531 inline double normal(double m, double s){ 00532 return MLib::normal(m, s); 00533 } 00534 00535 inline double erlang(double n, double x){ 00536 return MLib::erlang(n, x); 00537 } 00538 00539 inline double pareto(double k, double a){ 00540 return MLib::pareto(k, a); 00541 } 00542 00543 inline double lognormal(double a, double b){ 00544 return MLib::lognormal(a, b); 00545 } 00546 00547 inline double chisquare(double n){ 00548 return MLib::chisquare(n); 00549 } 00550 00551 inline long bernoulli(double p){ 00552 return MLib::bernoulli(p); 00553 } 00554 00555 inline long equilikely(long a, long b){ 00556 return MLib::equilikely(a, b); 00557 } 00558 00559 inline long binomial(long n, double p){ 00560 return MLib::binomial(n, p); 00561 } 00562 00563 inline long geometric(double p){ 00564 return MLib::geometric(p); 00565 } 00566 00567 inline long bpascal(long n, double p){ 00568 return MLib::bpascal(n, p); 00569 } 00570 00571 inline long poisson(double m){ 00572 return MLib::poisson(m); 00573 } 00574 00575 inline const mvar& choice(const mvar& seq){ 00576 return MLib::choice(seq); 00577 } 00578 00579 inline mvec randomSequence(long a, long b){ 00580 return MLib::randomSequence(a, b); 00581 } 00582 00583 inline mvar mixedDistribution(const mvar& v){ 00584 return MLib::mixedDistribution(v); 00585 } 00586 00587 inline mvar degrees(const mvar& d){ 00588 return MLib::degrees(d); 00589 } 00590 00591 inline double mpi(){ 00592 return MLib::pi(); 00593 } 00594 00595 inline double sqrt(double v){ 00596 return MLib::sqrt(v); 00597 } 00598 00599 inline double pow(double v, double exponent){ 00600 return MLib::pow(v, exponent); 00601 } 00602 00603 inline double abs(double v){ 00604 return MLib::abs(v); 00605 } 00606 00607 inline double log10(double v){ 00608 return MLib::log10(v); 00609 } 00610 00611 inline double cos(double v){ 00612 return MLib::cos(v); 00613 } 00614 00615 inline double acos(double v){ 00616 return MLib::acos(v); 00617 } 00618 00619 inline double cosh(double v){ 00620 return MLib::cosh(v); 00621 } 00622 00623 inline double sin(double v){ 00624 return MLib::sin(v); 00625 } 00626 00627 inline double asin(double v){ 00628 return MLib::asin(v); 00629 } 00630 00631 inline double sinh(double v){ 00632 return MLib::sinh(v); 00633 } 00634 00635 inline double tan(double v){ 00636 return MLib::tan(v); 00637 } 00638 00639 inline double atan(double v){ 00640 return MLib::atan(v); 00641 } 00642 00643 inline double atan2(double y, double x){ 00644 return MLib::atan2(y, x); 00645 } 00646 00647 inline double tanh(double v){ 00648 return MLib::tanh(v); 00649 } 00650 00651 inline double inf(){ 00652 return MLib::inf(); 00653 } 00654 00655 inline double negInf(){ 00656 return MLib::negInf(); 00657 } 00658 00659 inline double floor(double v){ 00660 return MLib::floor(v); 00661 } 00662 00663 inline double ceil(double v){ 00664 return MLib::ceil(v); 00665 } 00666 00667 inline double round(double v, double precision=1){ 00668 return MLib::round(v, precision); 00669 } 00670 00671 inline bool nearInteger(double v, mvar& n){ 00672 return MLib::nearInteger(v, n); 00673 } 00674 00675 inline double mdistance(const mvar& u, const mvar& v){ 00676 return MLib::distance(u, v); 00677 } 00678 00679 inline mvar scaleVector(const mvar& u, double magnitude){ 00680 return MLib::scaleVector(u, magnitude); 00681 } 00682 00683 inline mvec vectorRange(const mvar& b){ 00684 return MLib::vectorRange(b); 00685 } 00686 00687 inline mvec vectorRange(const mvar& a, const mvar& b){ 00688 return MLib::vectorRange(a, b); 00689 } 00690 00691 inline mvec vectorRange(const mvar& a, const mvar& b, const mvar& inc){ 00692 return MLib::vectorRange(a, b, inc); 00693 } 00694 00695 inline mlist listRange(const mvar& b){ 00696 return MLib::listRange(b); 00697 } 00698 00699 inline mlist listRange(const mvar& a, const mvar& b){ 00700 return MLib::listRange(a, b); 00701 } 00702 00703 inline mlist listRange(const mvar& a, const mvar& b, const mvar& inc){ 00704 return MLib::listRange(a, b, inc); 00705 } 00706 00707 inline mvar clamp(const mvar& v, const mvar& min, const mvar& max){ 00708 return MLib::clamp(v, min, max); 00709 } 00710 00711 inline void sleep(double secs){ 00712 MLib::sleep(secs); 00713 } 00714 00715 inline void print(const mstr& str){ 00716 MLib::print(str); 00717 } 00718 00719 inline mstr repeatString(const mstr& str, int n){ 00720 return MLib::repeatString(str, n); 00721 } 00722 00723 inline mvar mergeSymbolicMaps(const mvar& m1, const mvar& m2){ 00724 return MLib::mergeSymbolicMaps(m1, m2); 00725 } 00726 00727 inline bool hasArg(const mvar& key){ 00728 return MLib::hasArg(key); 00729 } 00730 00731 inline mvar args(){ 00732 return MLib::args(); 00733 } 00734 00735 inline void setArgs(const mvar& args){ 00736 MLib::setArgs(args); 00737 } 00738 00739 inline mvar arg(const mvar& key){ 00740 return MLib::arg(key); 00741 } 00742 00743 inline mvar arg(const mvar& key, const mvar& def){ 00744 return MLib::arg(key, def); 00745 } 00746 00747 inline void setArg(const mvar& key, const mvar& value){ 00748 MLib::setArg(key, value); 00749 } 00750 00751 inline void argDefault(const mvar& key, const mvar& value){ 00752 MLib::argDefault(key, value); 00753 } 00754 00755 inline double systemTime(){ 00756 return MLib::systemTime(); 00757 } 00758 00759 inline mstr formatTime(double t, const mstr& format){ 00760 return MLib::formatTime(t, format); 00761 } 00762 00763 inline void setDefaultPrecision(size_t bits){ 00764 MLib::setDefaultPrecision(bits); 00765 } 00766 00767 inline mstr formatTime(double t){ 00768 return MLib::formatTime(t); 00769 } 00770 00771 inline mvec crossProduct(const mvec& u, const mvec& v){ 00772 return MLib::crossProduct(u, v); 00773 } 00774 00775 inline mvar dotProduct(const mvec& u, const mvec& v){ 00776 return MLib::dotProduct(u, v); 00777 } 00778 } 00779 00780 } // end namespace Meta 00781 00782 #endif // ANDROMETA_M_LIB_H
1.7.6.1