NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
functionimplementation.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2014 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20/*
21 * Implementierung der Parser-Funktionen
22 */
24#define _USE_MATH_DEFINES
25
26#include <cstdlib>
27#include <cmath>
28#include <fstream>
29#include <string>
30#include <iostream>
31#include <locale>
32#include <limits>
33#include <ios>
34#include <iomanip>
35#include <numeric>
36#include <ctime>
37#include <csignal>
38#include <boost/math/common_factor.hpp>
39#include <gsl/gsl_sf.h>
40#include <noise/noise.h>
41
42#include "student_t.hpp"
43#include "../datamanagement/memorymanager.hpp"
44#include "../utils/tools.hpp"
45#include "../version.h"
46
47using namespace std;
48
49int nErrorIndices[2] = {-1,-1};
50string sErrorToken = "";
51extern time_t tTimeZero;
52volatile sig_atomic_t exitsignal = 0;
53
54/*
55 * Ende der globalen Variablen
56 */
57
58// --> Umrechnungsfunktionen: diese werden aufgerufen, wenn eine spezielle Syntax verwendet wird <--
67{
68 if (isinf(a_fVal) || isnan(a_fVal))
69 return NAN;
70 return a_fVal * 1e6;
71}
72
73
82{
83 if (isinf(a_fVal) || isnan(a_fVal))
84 return NAN;
85 return a_fVal * 1e-3;
86}
87
88
97{
98 if (isinf(a_fVal) || isnan(a_fVal))
99 return NAN;
100 return a_fVal * 1e9;
101}
102
103
112{
113 if (isinf(a_fVal) || isnan(a_fVal))
114 return NAN;
115 return a_fVal * 1e3;
116}
117
118
127{
128 if (isinf(a_fVal) || isnan(a_fVal))
129 return NAN;
130 return a_fVal * 1e-6;
131}
132
133
142{
143 if (isinf(a_fVal) || isnan(a_fVal))
144 return NAN;
145 return a_fVal * 1e-9;
146}
147
148
158{
159 if (isinf(v) || isnan(v))
160 return NAN;
161 return v == 0.0;
162}
163
164
174{
175 return v;
176}
177
178
179// --> Einheitenumrechnung: eV, fm, A, b, Torr, AU, etc... <--
188{
189 if (isinf(v) || isnan(v))
190 return NAN;
191 return v * 1.60217657e-19;
192}
193
194
203{
204 if (isinf(v) || isnan(v))
205 return NAN;
206 return v * 1e-15;
207}
208
209
218{
219 if (isinf(v) || isnan(v))
220 return NAN;
221 return v * 1e-10;
222}
223
224
233{
234 if (isinf(v) || isnan(v))
235 return NAN;
236 return v * 1e-28;
237}
238
239
248{
249 if (isinf(v) || isnan(v))
250 return NAN;
251 return v * 101325.0/760.0;
252}
253
254
263{
264 if (isinf(v) || isnan(v))
265 return NAN;
266 return v * 149597870700.0;
267}
268
269
278{
279 if (isinf(v) || isnan(v))
280 return NAN;
281 return v * 9460730472580800.0;
282}
283
284
293{
294 if (isinf(v) || isnan(v))
295 return NAN;
296 return v * 30856775777948584.2;
297}
298
299
308{
309 if (isinf(v) || isnan(v))
310 return NAN;
311 return v * 1609.344;
312}
313
314
323{
324 if (isinf(v) || isnan(v))
325 return NAN;
326 return v * 0.9144;
327}
328
329
338{
339 if (isinf(v) || isnan(v))
340 return NAN;
341 return v * 0.3048;
342}
343
344
353{
354 if (isinf(v) || isnan(v))
355 return NAN;
356 return v * 0.0254;
357}
358
359
368{
369 if (isinf(v) || isnan(v))
370 return NAN;
371 return v * 4.1868;
372}
373
374
383{
384 if (isinf(v) || isnan(v))
385 return NAN;
386 return v * 6894.75729;
387}
388
389
398{
399 if (isinf(v) || isnan(v))
400 return NAN;
401 return v * 463.0 / 900.0;
402}
403
404
413{
414 if (isinf(v) || isnan(v))
415 return NAN;
416 return v * 1e-3;
417}
418
419
428{
429 if (isinf(v) || isnan(v))
430 return NAN;
431 return v / 3.6;
432}
433
434
443{
444 if (isinf(v) || isnan(v))
445 return NAN;
446 return v * 1.609334 / 3.6;
447}
448
449
458{
459 if (isinf(v) || isnan(v))
460 return NAN;
461 return v + 273.15;
462}
463
464
473{
474 if (isinf(v) || isnan(v))
475 return NAN;
476 return (v + 459.67) * 5.0 / 9.0;
477}
478
479
488{
489 if (isinf(v) || isnan(v))
490 return NAN;
491 return v * 3.7e10;
492}
493
494
503{
504 if (isinf(v) || isnan(v))
505 return NAN;
506 return v * 1e-4;
507}
508
509
518{
519 if (isinf(v) || isnan(v))
520 return NAN;
521 return v * 1e-1;
522}
523
524
533{
534 if (isinf(v) || isnan(v))
535 return NAN;
536 return v * 6.022140857E23;
537}
538
539
549{
550 return value_type(v.imag() != 0.0 ? -v.imag() : 0.0, v.real());
551}
552
553
563{
564 return v.real();
565}
566
567
577{
578 return v.imag();
579}
580
581
592{
593 return value_type(std::abs(v), std::arg(v));
594}
595
596
607{
608 return std::polar(v.real(), v.imag());
609}
610
611
621{
622 return std::conj(v);
623}
624
625
636{
637 return value_type(re.real(), im.real());
638}
639
640
650{
651 if (isnan(v) || isinf(v))
652 return NAN;
653 value_type vResult = 1.0; // Ausgabe-Variable
654 // --> Falls v == 0 ist, dann ist die Fakultaet 1 und nicht 0. Fangen wir hier ab <--
655 if (intCast(v) == 0)
656 return 1;
657 if (intCast(v) < 0)
658 return NAN;
659
660 /* --> Zaehlschleife, die die Fakultaet bildet: allerdings in der Form 1*2*3*...*(n-1)*n und nicht
661 * in der Form, wie sie normal definiert wird: n*(n-1)*(n-2)*...*3*2*1 <--
662 */
663 for (int i = 1; i <= abs(intCast(v)); i++)
664 {
665 vResult *= i;
666 }
667 return vResult;
668}
669
670
680{
681 if (isnan(v) || isinf(v))
682 return NAN;
683 value_type vResult = 1.0;
684 if (intCast(v) < 0)
685 return NAN;
686 for (int n = intCast(fabs(v)); n > 0; n -= 2)
687 {
688 vResult *= n;
689 }
690 return vResult;
691}
692
693
704{
705 if (isnan(v1) || isnan(v2) || isinf(v1) || isinf(v2))
706 return NAN;
707 /* --> Bevor wir die bekannte Formel verwenden, pruefen wir einige Spezialfaelle, die den
708 * Algorithmus deutlich beschleunigen. Hier sei der Artikel auf Wikipedia zum Binomial-
709 * koeffzienten empfohlen <--
710 */
711 if (intCast(v2) < 0 || intCast(v1) < 0)
712 return NAN;
713 else if (intCast(v2) > intCast(v1)) // v2 > v1 ==> binom = 0!
714 return 0;
715 else if (intCast(v1) == intCast(v2) || (intCast(v1) != 0 && intCast(v2) == 0)) // v1 == v2 oder v2 == 0 und v1 != 0 ==> binom = 1!
716 return 1;
717 else if (intCast(v2) == 1 || intCast(v2) == intCast(v1)-1) // v2 == 1 oder v2 == v1-1 ==> binom = v1!
718 return intCast(v1);
719 else if (intCast(v2) == 2 && intCast(v2) < intCast(v1)) // v2 == 2 und v2 < v1 ==> binom = v1*(v1-1) / v2!
720 return intCast(v1)*(intCast(v1)-1)/intCast(v2);
721 else
722 {
723 /* --> In allen anderen Faellen muessen wir den Binomialkoeffzienten muehsam mithilfe der Formel
724 * binom(v1,v2) = v1!/(v2!*(v1-v2)!) ausrechnen. Das machen wir, indem wir die Funktion
725 * parser_Faculty(value_type) aufrufen <--
726 */
727 return parser_Faculty(v1) / (parser_Faculty(v2)*parser_Faculty(intCast(v1) - intCast(v2)));
728 }
729}
730
731
741value_type parser_Num(const value_type* vElements, int nElements)
742{
743 int nReturn = nElements;
744
745 for (int i = 0; i < nElements; i++)
746 {
747 if (isnan(vElements[i]) || isinf(vElements[i]))
748 nReturn--;
749 }
750
751 return nReturn;
752}
753
754
765value_type parser_Cnt(const value_type* vElements, int nElements)
766{
767 return nElements;
768}
769
770
781value_type parser_Std(const value_type* vElements, int nElements)
782{
783 value_type vStd = 0.0;
784 value_type vMean = parser_Avg(vElements, nElements);
785
786 for (int i = 0; i < nElements; i++)
787 {
788 if (!isnan(vElements[i]))
789 vStd += (vElements[i] - vMean) * conj(vElements[i] - vMean);
790 }
791
792 return sqrt(vStd / (parser_Num(vElements, nElements)-1.0));
793}
794
795
805value_type parser_product(const value_type* vElements, int nElements)
806{
807 value_type vProd = 1.0;
808
809 for (int i = 0; i < nElements; i++)
810 {
811 if (!isnan(vElements[i]))
812 vProd *= vElements[i];
813 }
814
815 return vProd;
816}
817
818
828value_type parser_Norm(const value_type* vElements, int nElements)
829{
830 value_type vResult = 0.0;
831
832 for (int i = 0; i < nElements; i++)
833 {
834 if (!isnan(vElements[i]))
835 vResult += vElements[i] * conj(vElements[i]);
836 }
837
838 return sqrt(vResult);
839}
840
841
851value_type parser_Med(const value_type* vElements, int nElements)
852{
853 Memory _mem;
854
855 for (int i = 0; i < nElements; i++)
856 _mem.writeData(i, 0, vElements[i]);
857
858 return _mem.med(VectorIndex(0, nElements-1), VectorIndex(0));
859}
860
861
871value_type parser_Pct(const value_type* vElements, int nElements)
872{
873 Memory _mem;
874
875 for (int i = 0; i < nElements-1; i++)
876 _mem.writeData(i, 0, vElements[i]);
877
878 return _mem.pct(VectorIndex(0, nElements-2), VectorIndex(0), vElements[nElements-1]);
879}
880
881
891value_type parser_compare(const value_type* vElements, int nElements)
892{
893 enum
894 {
895 RETURN_VALUE = 1,
896 RETURN_LE = 2,
897 RETURN_GE = 4,
898 RETURN_FIRST = 8
899 };
900
901 int nType = 0;
902
903 if (nElements < 3)
904 return NAN;
905
906 value_type vRef = vElements[nElements-2];
907 value_type vKeep = vRef;
908 int nKeep = -1;
909
910 if (vElements[nElements-1].real() > 0)
911 nType = RETURN_GE;
912 else if (vElements[nElements-1].real() < 0)
913 nType = RETURN_LE;
914
915 switch (intCast(fabs(vElements[nElements-1])))
916 {
917 case 2:
918 nType |= RETURN_VALUE;
919 break;
920 case 3:
921 nType |= RETURN_FIRST;
922 break;
923 case 4:
924 nType |= RETURN_FIRST | RETURN_VALUE;
925 break;
926 }
927
928 for (int i = 0; i < nElements-2; i++)
929 {
930 if (isnan(vElements[i]) || isinf(vElements[i]))
931 continue;
932
933 if (vElements[i] == vRef)
934 {
935 if (nType & RETURN_VALUE)
936 return vElements[i];
937
938 return i+1;
939 }
940 else if (nType & RETURN_GE && vElements[i].real() > vRef.real())
941 {
942 if (nType & RETURN_FIRST)
943 {
944 if (nType & RETURN_VALUE)
945 return vElements[i].real();
946
947 return i+1;
948 }
949
950 if (nKeep == -1 || vElements[i].real() < vKeep.real())
951 {
952 vKeep = vElements[i].real();
953 nKeep = i;
954 }
955 else
956 continue;
957 }
958 else if (nType & RETURN_LE && vElements[i].real() < vRef.real())
959 {
960 if (nType & RETURN_FIRST)
961 {
962 if (nType & RETURN_VALUE)
963 return vElements[i].real();
964
965 return i+1;
966 }
967
968 if (nKeep == -1 || vElements[i].real() > vKeep.real())
969 {
970 vKeep = vElements[i].real();
971 nKeep = i;
972 }
973 else
974 continue;
975 }
976 }
977
978 if (nKeep == -1)
979 return NAN;
980 else if (nType & RETURN_VALUE)
981 return vKeep;
982
983 return nKeep+1;
984}
985
986
997value_type parser_and(const value_type* vElements, int nElements)
998{
999 for (int i = 0; i < nElements; i++)
1000 {
1001 if (isnan(vElements[i]) || vElements[i] == 0.0)
1002 return 0.0;
1003 }
1004
1005 return 1.0;
1006}
1007
1008
1019value_type parser_or(const value_type* vElements, int nElements)
1020{
1021 for (int i = 0; i < nElements; i++)
1022 {
1023 if (vElements[i] != 0.0 && !isnan(vElements[i]))
1024 return 1.0;
1025 }
1026
1027 return 0.0;
1028}
1029
1030
1041value_type parser_xor(const value_type* vElements, int nElements)
1042{
1043 bool isTrue = false;
1044 for (int i = 0; i < nElements; i++)
1045 {
1046 if (vElements[i] != 0.0 && !isnan(vElements[i]))
1047 {
1048 if (!isTrue)
1049 isTrue = true;
1050 else
1051 return 0.0;
1052 }
1053 }
1054 if (isTrue)
1055 return 1.0;
1056 return 0.0;
1057}
1058
1059
1069value_type parser_polynomial(const value_type* vElements, int nElements)
1070{
1071 if (!nElements)
1072 return NAN;
1073 else if (nElements == 1)
1074 return 0.0;
1075
1076 value_type dResult = vElements[1];
1077
1078 for (int i = 2; i < nElements; i++)
1079 dResult += vElements[i] * intPower(vElements[0], i-1);
1080
1081 return dResult;
1082}
1083
1084
1094value_type parser_perlin(const value_type* vElements, int nElements)
1095{
1096 // perlin(x,y,z,seed,freq,oct,pers)
1097 if (!nElements)
1098 return NAN;
1099
1100 noise::module::Perlin perlinNoise;
1101
1102 switch (nElements)
1103 {
1104 case 1:
1105 return perlinNoise.GetValue(vElements[0].real(), 0, 0);
1106 case 2:
1107 return perlinNoise.GetValue(vElements[0].real(), vElements[1].real(), 0);
1108 case 3:
1109 return perlinNoise.GetValue(vElements[0].real(), vElements[1].real(), vElements[2].real());
1110 case 7: // fallthrough intended
1111 perlinNoise.SetPersistence(vElements[6].real());
1112 case 6: // fallthrough intended
1113 perlinNoise.SetOctaveCount(intCast(vElements[5]));
1114 case 5: // fallthrough intended
1115 perlinNoise.SetFrequency(vElements[4].real());
1116 case 4:
1117 perlinNoise.SetSeed(intCast(vElements[3].real()));
1118 return perlinNoise.GetValue(vElements[0].real(), vElements[1].real(), vElements[2].real());
1119 }
1120
1121 return NAN;
1122}
1123
1124
1134value_type parser_Sum(const value_type* vElements, int nElements)
1135{
1136 value_type fRes = 0;
1137
1138 for (int i = 0; i < nElements; ++i)
1139 {
1140 if (!isnan(vElements[i]))
1141 fRes += vElements[i];
1142 }
1143
1144 return fRes;
1145}
1146
1147
1157value_type parser_Avg(const value_type* vElements, int nElements)
1158{
1159 return parser_Sum(vElements, nElements) / parser_Num(vElements, nElements);
1160}
1161
1162
1172value_type parser_Min(const value_type* vElements, int nElements)
1173{
1174 value_type fRes = vElements[0].real();
1175
1176 for (int i = 0; i < nElements; ++i)
1177 {
1178 if (!isnan(fRes))
1179 break;
1180
1181 if (!isnan(vElements[i].real()))
1182 fRes = vElements[i].real();
1183 }
1184
1185 if (isnan(fRes))
1186 return fRes;
1187
1188 for (int i = 0; i < nElements; ++i)
1189 {
1190 if (!isnan(vElements[i].real()))
1191 fRes = std::min(fRes.real(), vElements[i].real());
1192 }
1193
1194 return fRes;
1195}
1196
1197
1207value_type parser_Max(const value_type* vElements, int nElements)
1208{
1209 value_type fRes = vElements[0].real();
1210
1211 for (int i = 0; i < nElements; ++i)
1212 {
1213 if (!isnan(fRes))
1214 break;
1215
1216 if (!isnan(vElements[i].real()))
1217 fRes = vElements[i].real();
1218 }
1219
1220 if (isnan(fRes))
1221 return fRes;
1222
1223 for (int i = 0; i < nElements; ++i)
1224 {
1225 if (!isnan(vElements[i].real()))
1226 fRes = std::max(fRes.real(), vElements[i].real());
1227 }
1228
1229 return fRes;
1230}
1231
1232
1242value_type parser_MinPos(const value_type* vElements, int nElements)
1243{
1244 vector<value_type> vData(vElements, vElements+nElements);
1245 vData.push_back(parser_Min(vElements, nElements));
1246 vData.push_back(0);
1247
1248 return parser_compare(&vData[0], vData.size());
1249}
1250
1251
1261value_type parser_MaxPos(const value_type* vElements, int nElements)
1262{
1263 vector<value_type> vData(vElements, vElements+nElements);
1264 vData.push_back(parser_Max(vElements, nElements));
1265 vData.push_back(0);
1266
1267 return parser_compare(&vData[0], vData.size());
1268}
1269
1270
1280value_type parser_round(const value_type& vToRound, const value_type& vDecimals)
1281{
1282 if (isinf(vToRound) || isinf(vDecimals) || isnan(vToRound) || isnan(vDecimals))
1283 return NAN;
1284
1285 double dDecimals = intPower(10, -abs(intCast(vDecimals)));
1286 value_type vRounded = vToRound / dDecimals;
1287 vRounded = value_type(std::round(vRounded.real()), std::round(vRounded.imag()));
1288 return vRounded * dDecimals;
1289}
1290
1291
1301{
1302 if (isinf(v) || isnan(v))
1303 return NAN;
1304
1305 return v / 180.0 * M_PI;
1306}
1307
1308
1318{
1319 if (isinf(v) || isnan(v))
1320 return NAN;
1321
1322 return v / M_PI * 180.0;
1323}
1324
1325
1338{
1339 if (isinf(vl.real()) || isnan(vl.real())
1340 || isinf(vm.real()) || isnan(vm.real())
1341 || isinf(theta.real()) || isnan(theta.real())
1342 || isinf(phi.real()) || isnan(phi.real()))
1343 return NAN;
1344
1345 int l = intCast(fabs(vl));
1346 int m = intCast(vm);
1347
1348 if (abs(m) > l)
1349 return NAN;
1350 else
1351 return sqrt((2.0*l+1.0) * parser_Faculty(l-m) / (4.0 * M_PI * parser_Faculty(l+m)))
1352 * parser_AssociatedLegendrePolynomial(l, m, cos(theta.real())) * exp(value_type(0, m*phi.real()));
1353
1354 return 0.0;
1355}
1356
1357
1370{
1371 if (isinf(vl.real()) || isnan(vl.real())
1372 || isinf(vm.real()) || isnan(vm.real())
1373 || isinf(theta.real()) || isnan(theta.real())
1374 || isinf(phi.real()) || isnan(phi.real()))
1375 return NAN;
1376
1377 int l = intCast(fabs(vl));
1378 int m = intCast(vm);
1379
1380 if (abs(m) > l)
1381 return NAN;
1382 else
1383 return sqrt((2.0*l+1.0) * parser_Faculty(l-m) / (4.0 * M_PI * parser_Faculty(l+m)))
1384 * parser_AssociatedLegendrePolynomial(l, m, cos(theta.real())) * sin(m*phi.real());
1385
1386 return 0.0;
1387}
1388
1389
1401value_type parser_Zernike(const value_type& vn, const value_type& vm, const value_type& rho, const value_type& phi)
1402{
1403 if (isinf(vn.real()) || isnan(vn.real())
1404 || isinf(vm.real()) || isnan(vm.real())
1405 || isinf(rho) || isnan(rho)
1406 || isinf(phi) || isnan(phi))
1407 return NAN;
1408
1409 int n = intCast(vn);
1410 int m = intCast(vm);
1411
1412 if (n < abs(m))
1413 return NAN;
1414
1415 if (m < 0)
1416 return parser_ZernikeRadial(n, -m, rho) * sin(-(double)m*phi);
1417 else
1418 return parser_ZernikeRadial(n, m, rho) * cos((double)m*phi);
1419}
1420
1421
1433{
1434 value_type vReturn = 0;
1435 value_type vNorm = 0;
1436
1437 if (fabs(rho) > 1.0)
1438 return NAN;
1439
1440 if ((n-m) % 2)
1441 return 0.0;
1442
1443 for (int k = 0; k <= (n-m)/2; k++)
1444 {
1445 if (k % 2)
1446 {
1447 vReturn -= parser_Faculty(n-k)*intPower(rho, n-2*k)/(parser_Faculty(k)*parser_Faculty((n+m)/2.0-k)*parser_Faculty((n-m)/2.0-k));
1448 vNorm -= parser_Faculty(n-k)/(parser_Faculty(k)*parser_Faculty((n+m)/2.0-k)*parser_Faculty((n-m)/2.0-k));
1449 }
1450 else
1451 {
1452 vReturn += parser_Faculty(n-k)*intPower(rho, n-2*k)/(parser_Faculty(k)*parser_Faculty((n+m)/2.0-k)*parser_Faculty((n-m)/2.0-k));
1453 vNorm += parser_Faculty(n-k)/(parser_Faculty(k)*parser_Faculty((n+m)/2.0-k)*parser_Faculty((n-m)/2.0-k));
1454 }
1455 }
1456
1457 return vReturn/vNorm;
1458}
1459
1460
1470{
1471 if (isinf(v) || isnan(v))
1472 return NAN;
1473 if (v == 0.0)
1474 return 1.0;
1475 else
1476 return sin(v)/v;
1477}
1478
1479
1490{
1491 if (isinf(vn) || isinf(vc) || isnan(vn) || isnan(vc))
1492 return NAN;
1493 int n = intCast(fabs(vn));
1494 double v = vc.real();
1495 if (!n && v == 0.0)
1496 return 1.0;
1497 else if (!n)
1498 return sin(v)/v;
1499 else if (n && v == 0.0)
1500 return 0.0;
1501 else if (n == 1)
1502 return sin(v)/(v*v) - cos(v)/v;
1503 else if (n == 2)
1504 return (3.0/(v*v)-1.0)*sin(v)/v-3.0*cos(v)/(v*v);
1505 else if (n == 3)
1506 return (15.0/(v*v*v)-6.0/v)*sin(v)/v-(15.0/(v*v)-1.0)*cos(v)/v;
1507 else if (n == 4)
1508 return 5.0/(v*v*v*v)*(2.0*v*v-21.0)*cos(v) + 1.0/(v*v*v*v*v)*(v*v*v*v - 45.0*v*v + 105.0)*sin(v);
1509 else if (n == 5)
1510 return 15.0/(v*v*v*v*v*v)*(v*v*v*v - 28.0*v*v + 63.0) * sin(v) + 1.0/(v*v*v*v*v)*(-v*v*v*v + 105.0*v*v - 945.0)*cos(v);
1511 else if (n == 6)
1512 return (-intPower(v,6)+210.0*v*v*v*v-4725.0*v*v+10395.0)*sin(v)/intPower(v,7)-21.0*(v*v*v*v-60.0*v*v+495.0)*cos(v)/intPower(v,6);
1513 else if (n == 7)
1514 return (intPower(v,6)-378.0*v*v*v*v+17325.0*v*v-135135.0)*cos(v)/intPower(v,7) - 7.0*(4.0*intPower(v,6)-450.0*v*v*v*v+8910.0*v*v-19305.0)*sin(v)/intPower(v,8);
1515 else if (n == 8)
1516 return 9.0*(4.0*intPower(v,6)-770.0*v*v*v*v+30030.0*v*v-225225.0)*cos(v)/intPower(v,8)+(intPower(v,8)-630.0*intPower(v,6)+51975.0*v*v*v*v-945945.0*v*v+2027025.0)*sin(v)/intPower(v,9);
1517 else if (n == 9)
1518 return 45.0*(intPower(v,8)-308.0*intPower(v,6)+21021.0*v*v*v*v-360360.0*v*v+765765.0)*sin(v)/intPower(v,10)+(-intPower(v,8)+990.0*intPower(v,6)-135135.0*v*v*v*v+4729725.0*v*v-34459425.0)*cos(v)/intPower(v,9);
1519 else if (n == 10)
1520 return (-intPower(v,10)+1485.0*intPower(v,8)-315315.0*intPower(v,6)+18918900.0*v*v*v*v-310134825.0*v*v+654729075.0)*sin(v)/intPower(v,11)-55.0*(intPower(v,8)-468.0*intPower(v,6)+51597.0*v*v*v*v-1670760.0*v*v+11904165.0)*cos(v)/intPower(v,10);
1521 else
1522 {
1523 return gsl_sf_bessel_jl(intCast(vn), fabs(v));
1524 }
1525 return 0.0;
1526}
1527
1528
1539{
1540 if (isinf(vn) || isnan(vn) || isinf(vc) || isnan(vc))
1541 return NAN;
1542 int n = intCast(fabs(vn));
1543 double v = vc.real();
1544 if (v == 0.0)
1545 return INFINITY;
1546 else if (!n)
1547 return -cos(v)/v;
1548 else if (n == 1)
1549 return -cos(v)/(v*v) - sin(v)/v;
1550 else if (n == 2)
1551 return (-3.0/(v*v)+1.0)*cos(v)/v - 3.0*sin(v)/(v*v);
1552 else if (n == 3)
1553 return (-15.0/(v*v*v)+6.0/v)*cos(v)/v - (15.0/(v*v)-1.0)*sin(v)/v;
1554 else if (n == 4)
1555 return 5.0/(v*v*v*v)*(2.0*v*v-21.0)*sin(v) + 1.0/(v*v*v*v*v)*(-v*v*v*v+45.0*v*v - 105.0)*cos(v);
1556 else if (n == 5)
1557 return 1.0/(v*v*v*v*v)*(-v*v*v*v + 105.0*v*v - 945.0)*sin(v) - 15.0/(v*v*v*v*v*v)*(v*v*v*v - 28.0*v*v + 63.0)*cos(v);
1558 else if (n == 6)
1559 return (intPower(v,6)-210.0*v*v*v*v+4725.0*v*v-10395.0)*cos(v)/intPower(v,7)-21.0*(v*v*v*v-60.0*v*v+495.0)*sin(v)/intPower(v,6);
1560 else if (n == 7)
1561 return 7.0*(4.0*intPower(v,6)-450.0*v*v*v*v+8910.0*v*v-19305.0)*cos(v)/intPower(v,8)+(intPower(v,6)-378.0*v*v*v*v-17325.0*v*v-135135.0)*sin(v)/intPower(v,7);
1562 else if (n == 8)
1563 return 9.0*(4.0*intPower(v,6)-770.0*v*v*v*v+30030.0*v*v-225225.0)*sin(v)/intPower(v,8)+(-intPower(v,8)+630.0*intPower(v,6)-51975.0*v*v*v*v+945945.0*v*v-2027025.0)*cos(v)/intPower(v,9);
1564 else if (n == 9)
1565 return (-intPower(v,8)+990.0*intPower(v,6)-135135.0*v*v*v*v+4729725.0*v*v-34459425.0)*sin(v)/intPower(v,9)-45.0*(intPower(v,8)-308.0*intPower(v,6)+21021.0*v*v*v*v-360360.0*v*v-765765.0)*cos(v)/intPower(v,10);
1566 else if (n == 10)
1567 return (intPower(v,10)-1485.0*intPower(v,8)+315315.0*intPower(v,6)-18918900.0*v*v*v*v+310134825.0*v*v-654729075.0)*cos(v)/intPower(v,11)-55.0*(intPower(v,8)-468.0*intPower(v,6)+51597.0*v*v*v*v-1670760.0*v*v+11904165.0)*sin(v)/intPower(v,10);
1568 else
1569 {
1570 return gsl_sf_bessel_yl(intCast(vn), fabs(v));
1571 }
1572 return 0.0;
1573}
1574
1575
1586{
1587 if (isinf(vn) || isnan(vn) || isinf(v) || isnan(v))
1588 return NAN;
1589 int n = intCast(fabs(vn));
1590
1591 value_type dResult = 0.0;
1592 for (int k = 0; k <= n/2; k++)
1593 {
1594 dResult += intPower(-1,k)*parser_Binom(n,k)*parser_Binom(2*(n-k),n)*intPower(v,n-2*k);
1595 }
1596 dResult *= intPower(2, -n);
1597 return dResult;
1598}
1599
1600
1613{
1614 if (isinf(vl) || isnan(vl) || isinf(vm) || isnan(vm) || isinf(v) || isnan(v))
1615 return NAN;
1616 int l = intCast(fabs(vl));
1617 int m = intCast(fabs(vm));
1618 if (m > l)
1619 return NAN;
1620 if (!m)
1621 return parser_LegendrePolynomial(l,v);
1622 else if (m < 0)
1624 else if (l == m)
1625 return intPower(-1.0,l)*parser_doubleFaculty((2.0*l-1.0))*pow(1.0-v*v,(double)l/2.0);//intPower(sqrt(1-v*v), l);
1626 else if (m == l-1)
1627 return v*(2.0*l-1.0)*intPower(-1.0,l-1)*parser_doubleFaculty((2.0*l-3.0))*pow(1.0-v*v,((double)l-1.0)/2.0);//intPower(sqrt(1-v*v), l-1);
1628 else
1629 return 1.0/(double)(l-m)*(v*(2.0*l-1)*parser_AssociatedLegendrePolynomial(l-1,m,v) - (double)(l+m-1)*parser_AssociatedLegendrePolynomial(l-2,m,v));
1630
1631 return 0.0;
1632}
1633
1634
1645{
1646 if (isinf(vn) || isnan(vn) || isinf(v) || isnan(v))
1647 return NAN;
1648 int n = intCast(fabs(vn));
1649
1650 value_type dResult = 0.0;
1651 for (int k = 0; k <= n; k++)
1652 {
1653 dResult += intPower(-v,k)*parser_Binom(n,k)/parser_Faculty(k);
1654 }
1655 return dResult;
1656}
1657
1658
1671{
1672 if (isinf(vn) || isnan(vn) || isinf(vk) || isnan(vk) || isinf(v) || isnan(v))
1673 return NAN;
1674 int n = intCast(fabs(vn));
1675 int k = intCast(fabs(vk));
1676// if (k > n)
1677// return NAN;
1678
1679 if (n == 0)
1680 return 1.0;
1681
1682 value_type dResult = 0.0;
1683 value_type vFaculty = parser_Faculty(n+k);
1684 for (int m = 0; m <= n; m++)
1685 {
1686 dResult += vFaculty * intPower(-v,m) / (parser_Faculty(n-m)*parser_Faculty(k+m)*parser_Faculty(m));
1687 }
1688 return dResult;
1689}
1690
1691
1702{
1703 if (isinf(vn) || isnan(vn) || isinf(v) || isnan(v))
1704 return NAN;
1705 int n = intCast(fabs(vn));
1706
1707 switch (n)
1708 {
1709 case 0: return 1.0;
1710 case 1: return 2.0*v;
1711 case 2: return 4.0*v*v - 2.0;
1712 case 3: return 8.0*v*v*v - 12.0*v;
1713 case 4: return 16.0*v*v*v*v - 48.0*v*v + 12.0;
1714 default: return 2.0*v*parser_HermitePolynomial(n-1,v) - 2.0*(double)(n-1)*parser_HermitePolynomial(n-2,v);
1715 }
1716 return 0.0;
1717}
1718
1719
1731{
1732 if (isinf(vN.real()) || isnan(vN.real()) || isinf(vZ.real()) || isnan(vZ.real()))
1733 return NAN;
1734 // nan/inf
1735 double a_V = 15.67;
1736 double a_S = 17.23;
1737 double a_F = 23.2875;
1738 double a_C = 0.714;
1739 double a_p = 11.2;
1740 double A = vN.real() + vZ.real();
1741 double dEnergy = 0.0;
1742 int delta = 0;
1743 unsigned int N = (unsigned int)intCast(parser_round(vN,0));
1744 unsigned int Z = (unsigned int)intCast(parser_round(vZ,0));
1745
1746
1747 if (A < 0 || vZ.real() < 0 || vN.real() < 0)
1748 return NAN;
1749 if (A == 0)
1750 return 0.0;
1751 if (N % 2 && Z % 2)
1752 delta = -1;
1753 else if (!(N % 2 || Z % 2))
1754 delta = 1;
1755
1756
1757 dEnergy = a_V*A - a_S*pow(A,2.0/3.0) - a_F*(vN.real()-vZ.real())*(vN.real()-vZ.real())/A - a_C*vZ.real()*(vZ.real()-1)/pow(A,1.0/3.0) + (double)delta*a_p/sqrt(A);
1758 if (dEnergy >= 0)
1759 return dEnergy;
1760 else
1761 return 0.0;
1762}
1763
1764
1774{
1775 if (isinf(v.real()) || isnan(v.real()))
1776 return NAN;
1777
1778 return v.real() >= 0.0;
1779}
1780
1781
1793{
1794 if (isinf(x.real()) || isnan(x.real()) || isinf(y.real()) || isnan(y.real()))
1795 return NAN;
1796 if (y.real() < 0)
1797 return M_PI+abs(M_PI + atan2(y.real(), x.real()));
1798 return atan2(y.real(), x.real());
1799}
1800
1801
1802// --> Polarwinkel theta <--
1815{
1816 if (isinf(x) || isnan(x) || isinf(y) || isnan(y) || isinf(z) || isnan(z))
1817 return NAN;
1818 if (x == 0.0 && y == 0.0 && z == 0.0)
1819 return M_PI/2;
1820 return acos(z/sqrt(x*conj(x)+y*conj(y)+z*conj(z)));
1821}
1822
1823
1834value_type parser_Random(const value_type& vRandMin, const value_type& vRandMax)
1835{
1836 if (isinf(vRandMin) || isnan(vRandMin) || isinf(vRandMax) || isnan(vRandMax))
1837 return NAN;
1838
1839 static uniform_real_distribution<double> randDist(0, 1);
1840 return randDist(getRandGenInstance()) * (vRandMax - vRandMin) + vRandMin;
1841}
1842
1843
1854value_type parser_gRandom(const value_type& vRandAvg, const value_type& vRandstd)
1855{
1856 if (isinf(vRandAvg) || isnan(vRandAvg) || isinf(vRandstd) || isnan(vRandstd))
1857 return NAN;
1858
1859 static normal_distribution<double> randDist(0, 1);
1860 return randDist(getRandGenInstance()) * fabs(vRandstd) + vRandAvg;
1861}
1862
1863
1873{
1874 if (isinf(x.real()) || isnan(x.real()))
1875 return NAN;
1876 return erf(x.real());
1877}
1878
1879
1889{
1890 if (isinf(x.real()) || isnan(x.real()))
1891 return NAN;
1892 return erfc(x.real());
1893}
1894
1895
1905{
1906 if (isinf(x) || isnan(x))
1907 return NAN;
1908
1909 if (x.imag() == 0.0)
1910 return tgamma(x.real());
1911
1912 gsl_sf_result lng;
1913 gsl_sf_result arg;
1914 gsl_sf_lngamma_complex_e(x.real(), x.imag(), &lng, &arg);
1915
1916 return std::polar(std::exp(lng.val), arg.val);
1917}
1918
1919
1929{
1930 return gsl_sf_airy_Ai(x.real(), GSL_PREC_DOUBLE);
1931}
1932
1933
1943{
1944 return gsl_sf_airy_Bi(x.real(), GSL_PREC_DOUBLE);
1945}
1946
1947
1958{
1959 if (n.real() >= 0.0)
1960 return gsl_sf_bessel_Jn(intCast(n), x.real());
1961 else
1962 return NAN;
1963}
1964
1965
1976{
1977 if (x != 0.0 && n.real() >= 0.0)
1978 return x.real()/fabs(x.real())*gsl_sf_bessel_Yn(intCast(n), fabs(x.real()));
1979 else
1980 return -INFINITY;
1981}
1982
1983
1994{
1995 double k = kc.real();
1996 double phi = phic.real();
1997
1998 if (isnan(k) || isnan(phi) || isinf(k) || isinf(phi))
1999 return NAN;
2000
2001 if (k < 0 || k >= 1)
2002 return NAN;
2003
2004 if (phi < 0 || phi > M_PI_2)
2005 {
2006 int nSign = 1;
2007 int nMultiple = floor(fabs(phi/M_PI_2));
2008
2009 if (phi < 0)
2010 nSign = -1;
2011
2012 if (!(nMultiple % 2)) // even
2013 return nSign*(nMultiple*gsl_sf_ellint_Kcomp(k,0) + gsl_sf_ellint_F(fabs(phi)-nMultiple*M_PI_2, k, 0));
2014 else // odd
2015 return nSign*((nMultiple+1)*gsl_sf_ellint_Kcomp(k,0) - gsl_sf_ellint_F(M_PI_2-(fabs(phi)-nMultiple*M_PI_2), k, 0));
2016 }
2017
2018 return gsl_sf_ellint_F(phi, k, 0);
2019}
2020
2021
2032{
2033 double phi = phic.real();
2034 double k = kc.real();
2035
2036 if (isnan(k) || isnan(phi) || isinf(k) || isinf(phi))
2037 return NAN;
2038
2039 if (k < 0 || k >= 1)
2040 return NAN;
2041
2042 if (phi < 0 || phi > M_PI_2)
2043 {
2044 int nSign = 1;
2045 int nMultiple = floor(fabs(phi/M_PI_2));
2046
2047 if (phi < 0)
2048 nSign = -1;
2049
2050 if (!(nMultiple%2)) // even
2051 return nSign*(nMultiple*gsl_sf_ellint_Ecomp(k,0) + gsl_sf_ellint_E(fabs(phi)-nMultiple*M_PI_2, k, 0));
2052 else // odd
2053 return nSign*((nMultiple+1)*gsl_sf_ellint_Ecomp(k,0) - gsl_sf_ellint_E(M_PI_2-(fabs(phi)-nMultiple*M_PI_2), k, 0));
2054 }
2055
2056 return gsl_sf_ellint_E(phi, k, 0);
2057}
2058
2059
2071{
2072 if (isnan(k.real()) || isnan(phi.real()) || isinf(k.real()) || isinf(phi.real()) || isnan(n.real()) || isinf(n.real()))
2073 return NAN;
2074
2075 if (k.real() < 0 || k.real() >= 1)
2076 return NAN;
2077
2078 if (phi.real() < 0 || phi.real() > M_PI_2)
2079 {
2080 int nSign = 1;
2081 int nMultiple = floor(fabs(phi.real()/M_PI_2));
2082
2083 if (phi.real() < 0)
2084 nSign = -1;
2085
2086 if (!(nMultiple%2)) // even
2087 return nSign*(nMultiple*gsl_sf_ellint_P(M_PI_2, k.real(), n.real(),0) + gsl_sf_ellint_P(fabs(phi.real())-nMultiple*M_PI_2, k.real(), n.real(), 0));
2088 else // odd
2089 return nSign*((nMultiple+1)*gsl_sf_ellint_P(M_PI_2, k.real(), n.real(),0) - gsl_sf_ellint_P(M_PI_2-(fabs(phi.real())-nMultiple*M_PI_2), k.real(), n.real(), 0));
2090 }
2091
2092 return gsl_sf_ellint_P(phi.real(), k.real(), n.real(), 0);
2093}
2094
2095
2107{
2108 if (isnan(k.real()) || isnan(phi.real()) || isinf(k.real()) || isinf(phi.real()) || isnan(n.real()) || isinf(n.real()))
2109 return NAN;
2110
2111 if (k.real() < 0 || k.real() >= 1)
2112 return NAN;
2113
2114 if (phi.real() < 0 || phi.real() > M_PI_2)
2115 {
2116 int nSign = 1;
2117 int nMultiple = floor(fabs(phi.real()/M_PI_2));
2118
2119 if (phi.real() < 0)
2120 nSign = -1;
2121
2122 if (!(nMultiple%2)) // even
2123 return nSign*(nMultiple*gsl_sf_ellint_D(M_PI_2, k.real(), n.real(), 0) + gsl_sf_ellint_D(fabs(phi.real())-nMultiple*M_PI_2, k.real(), n.real(), 0));
2124 else // odd
2125 return nSign*((nMultiple+1)*gsl_sf_ellint_D(M_PI_2, k.real(), n.real(), 0) - gsl_sf_ellint_D(M_PI_2-(fabs(phi.real())-nMultiple*M_PI_2), k.real(), n.real(), 0));
2126 }
2127
2128 return gsl_sf_ellint_D(phi.real(), k.real(), n.real(), 0);
2129}
2130
2131
2142{
2143 if (isnan(a.real()) || isnan(b.real()) || isinf(a.real()) || isinf(b.real()))
2144 return NAN;
2145
2146 if ((intCast(a) == (int)a.real() && a.real() < 0) || (intCast(b) == (int)b.real() && b.real() < 0))
2147 return NAN;
2148
2149 return gsl_sf_beta(a.real(), b.real());
2150}
2151
2152
2162static double ek(int k, int N)
2163{
2164 double sum = 0;
2165 static std::vector<double> vLookUp;
2166
2167 if ((int)vLookUp.size() > k-1)
2168 return vLookUp[k-1];
2169
2170 for (int j = k; j <= N; j++)
2171 sum += parser_Binom((double)N, (double)j).real();
2172
2173 vLookUp.push_back(sum);
2174
2175 return sum;
2176}
2177
2178
2188static std::complex<double> complex_zeta(const std::complex<double>& s)
2189{
2190 if (s == 1.0)
2191 return NAN;
2192
2193 std::complex<double> sum;
2194 static const int N = 20;
2195 static const double coeff = intPower(0.5, N);
2196
2197 for (int k = 1; k <= N; k++)
2198 {
2199 sum += ((k-1) % 2 ? -1.0 : 1.0) / std::pow(k, s);
2200 }
2201
2202 for (int k = N+1; k <= 2*N; k++)
2203 {
2204 sum += coeff * ((k-1) % 2 ? -1.0 : 1.0) * ek(k-N, N) / std::pow(k, s);
2205 }
2206
2207 return 1.0 / (1.0-std::pow(2.0, 1.0-s)) * sum;
2208}
2209
2210
2220{
2221 if (isnan(s) || isinf(s))
2222 return NAN;
2223
2224 // Use the functional equation to swap negative
2225 // real numbers into the positive half-plane
2226 if (s.real() < 0.0)
2227 return std::pow(2.0, s)*std::pow(M_PI, s-1.0)*sin(0.5*M_PI*s)*parser_gamma(1.0-s)*complex_zeta(1.0-s);
2228
2229 return complex_zeta(s);
2230}
2231
2232
2242{
2243 if (isnan(x.real()) || isinf(x.real()))
2244 return NAN;
2245
2246 return gsl_sf_clausen(x.real());
2247}
2248
2249
2259{
2260 if (isnan(x.real()) || isinf(x.real()))
2261 return NAN;
2262
2263 if (x.real() == 0.0)
2264 return NAN;
2265
2266 if ((int)x.real() == intCast(x) && x.real() > 0)
2267 return gsl_sf_psi_int(intCast(x));
2268 else
2269 return gsl_sf_psi(x.real());
2270}
2271
2272
2283{
2284 if (isnan(n.real()) || isnan(x.real()) || isinf(n.real()) || isinf(x.real()) || x.real() <= 0 || n.real() < 0)
2285 return NAN;
2286
2287 return gsl_sf_psi_n(intCast(n), x.real());
2288}
2289
2290
2300{
2301 if (isnan(x) || isinf(x))
2302 return NAN;
2303
2304 if (x.imag() == 0.0)
2305 return gsl_sf_dilog(x.real());
2306
2307 gsl_sf_result re;
2308 gsl_sf_result im;
2309
2310 gsl_sf_complex_dilog_xy_e(x.real(), x.imag(), &re, &im);
2311 return value_type(re.val, im.val);
2312}
2313
2314
2323{
2324 return value_type(floor(x.real()), floor(x.imag()));
2325}
2326
2327
2336{
2337 return value_type(ceil(x.real()), ceil(x.imag()));
2338}
2339
2340
2351{
2352 return (x.real() > x1.real() || x.real() < x0.real()) ? 0.0 : 1.0;
2353}
2354
2355
2369value_type parser_ivl(const value_type& x, const value_type& x0, const value_type& x1, const value_type& lborder, const value_type& rborder)
2370{
2371 double lb = lborder.real();
2372 double rb = rborder.real();
2373 if (lb < 0)
2374 lb = 0;
2375
2376 if (lb > 2)
2377 lb = 2;
2378
2379 if (rb < 0)
2380 rb = 0;
2381
2382 if (rb > 2)
2383 rb = 2;
2384
2385 if (x.real() < x0.real() && lb)
2386 return 0;
2387 else if (x.real() < x0.real())
2388 return 1;
2389
2390 if (x.real() == x0.real() && lb != 2)
2391 return 1;
2392 else if (x.real() == x0.real() && lb == 2)
2393 return 0;
2394
2395 if (x.real() > x1.real() && rb)
2396 return 0;
2397 else if (x.real() > x1.real())
2398 return 1;
2399
2400 if (x.real() == x1.real() && rb != 2)
2401 return 1;
2402 else if (x.real() == x1.real() && rb == 2)
2403 return 0;
2404
2405 return 1;
2406}
2407
2408
2420{
2421 if (vAlpha.real() >= 1.0 || vAlpha.real() <= 0.0 || vFreedoms.real() < 2.0)
2422 return NAN;
2423
2424 return student_t(intCast(vFreedoms), vAlpha.real());
2425}
2426
2427
2438{
2439 return boost::math::gcd(intCast(n), intCast(k));
2440}
2441
2442
2453{
2454 return boost::math::lcm(intCast(n), intCast(k));
2455}
2456
2457
2468{
2469 if (std::isinf(v2.real()) || std::isnan(v2.real()) || std::isinf(v2.imag()) || std::isnan(v2.imag()))
2470 return NAN;
2471
2472 mu::value_type div = v1 / v2;
2473 div = mu::value_type(std::floor(div.real()),
2474 std::floor(div.imag()));
2475
2476 return v1 - div * v2;
2477}
2478
2479
2490{
2491 if (isinf(v1) || isnan(v1) || isinf(v2) || isnan(v2))
2492 return NAN;
2493
2494 return (v1 != 0.0) xor (v2 != 0.0);
2495}
2496
2497
2508{
2509 if (isinf(v1) || isnan(v1) || isinf(v2) || isnan(v2))
2510 return NAN;
2511
2512 return intCast(v1) | intCast(v2);
2513}
2514
2515
2526{
2527 if (isinf(v1) || isnan(v1) || isinf(v2) || isnan(v2))
2528 return NAN;
2529
2530 return intCast(v1) & intCast(v2);
2531}
2532
2533
2544{
2545 if (isnan(v) || isinf(v))
2546 return NAN;
2547
2548 return 0.0;
2549}
2550
2551
2560{
2561 return to_double(sys_time_now());
2562}
2563
2564
2573{
2574 return (double)clock();
2575}
2576
2577
2587{
2588 Sleep(intCast(milliseconds));
2589 return intCast(milliseconds);
2590}
2591
2592
2603{
2604 if (isnan(b.real()) || isnan(x) || isinf(b.real()) || x.real() <= 0.0 || b.real() <= 0.0)
2605 return NAN;
2606
2607 if (isinf(x))
2608 return INFINITY;
2609
2610 return log10(x) / log10(b.real());
2611}
2612
2613
2622{
2624}
2625
2626
2636value_type parser_date(const value_type& vTime, const value_type& vType)
2637{
2638 sys_time_point tp = to_timePoint(vTime.real());
2639 int nType = (int)rint(vType.real());
2641
2642 switch (nType)
2643 {
2644 case 1:
2645 return int(ltm.m_ymd.year());
2646 case 2:
2647 return unsigned(ltm.m_ymd.month());
2648 case 3:
2649 return unsigned(ltm.m_ymd.day());
2650 case 4:
2651 return ltm.m_hours.count();
2652 case 5:
2653 return ltm.m_minutes.count();
2654 case 6:
2655 return ltm.m_seconds.count();
2656 case 7:
2657 return ltm.m_millisecs.count();
2658 case 8:
2659 return ltm.m_microsecs.count();
2660 case -1:
2661 return int(ltm.m_ymd.year())*10000.0 + unsigned(ltm.m_ymd.month())*100.0 + unsigned(ltm.m_ymd.day());
2662 case -2:
2663 return ltm.m_hours.count()*10000.0 + ltm.m_minutes.count()*100.0 + ltm.m_seconds.count() + ltm.m_millisecs.count()*1.0e-3;
2664 default:
2665 return (int(ltm.m_ymd.year())*10000.0 + unsigned(ltm.m_ymd.month())*100.0 + unsigned(ltm.m_ymd.day()))*1000000.0
2666 + ltm.m_hours.count()*10000.0 + ltm.m_minutes.count()*100.0 + ltm.m_seconds.count() + ltm.m_millisecs.count()*1.0e-3;
2667 }
2668
2669 return 0;
2670}
2671
2672
2682{
2683 return getWeekNum(to_timePoint(vTime.real()));
2684}
2685
2686
2696{
2697 return v != v;
2698}
2699
2700
2712value_type parser_interval(const value_type& v, const value_type& vLeft, const value_type& vRight)
2713{
2714 if (vRight.real() <= vLeft.real())
2715 return NAN;
2716
2717 if (v.real() <= vRight.real() && v.real() >= vLeft.real())
2718 return v.real();
2719
2720 return NAN;
2721}
2722
2723
2733{
2734 if (isnan(x) || isinf(x))
2735 return NAN;
2736
2737 if (sin(x) == 0.0)
2738 return INFINITY;
2739
2740 return cos(x) / sin(x);
2741}
2742
2743
2755value_type* parser_AddVariable(const char_type* a_szName, void* a_pUserData)
2756{
2757 // Cast the passed void pointer to a the data storage list
2758 std::list<mu::value_type*>* m_lDataStorage = static_cast<std::list<mu::value_type*>* >(a_pUserData);
2759
2760 // Create the storage for a new variable
2761 m_lDataStorage->push_back(new mu::value_type);
2762 *(m_lDataStorage->back()) = 0.0;
2763
2764 // Return the address of the newly created storage
2765 return m_lDataStorage->back();
2766}
2767
2768
2778{
2779 return 1.0 / std::cos(x);
2780}
2781
2782
2792{
2793 return 1.0 / std::sin(x);
2794}
2795
2796
2806{
2807 return std::acos(1.0 / x);
2808}
2809
2810
2820{
2821 return std::asin(1.0 / x);
2822}
2823
2824
2834{
2835 return 1.0 / std::cosh(x);
2836}
2837
2838
2848{
2849 return 1.0 / std::sinh(x);
2850}
2851
2852
2862{
2863 return std::acosh(1.0 / x);
2864}
2865
2866
2876{
2877 return std::asinh(1.0 / x);
2878}
2879
This class represents a single table in memory, or a - so to say - single memory page to be handled b...
Definition: memory.hpp:68
void writeData(int _nLine, int _nCol, const mu::value_type &_dData)
This member function writes the passed value to the selected position. The table is automatically enl...
Definition: memory.cpp:1219
mu::value_type pct(const VectorIndex &_vLine, const VectorIndex &_vCol, mu::value_type dPct=0.5) const
Implementation for the PCT multi argument function.
Definition: memory.cpp:2803
mu::value_type med(const VectorIndex &_vLine, const VectorIndex &_vCol) const
Implementation for the MED multi argument function.
Definition: memory.cpp:2736
This class abstracts all the index logics, i.e. the logical differences between single indices and in...
Definition: structures.hpp:42
CONSTCD11 date::year year() const NOEXCEPT
Definition: date.h:2928
CONSTCD11 date::day day() const NOEXCEPT
Definition: date.h:2930
CONSTCD11 date::month month() const NOEXCEPT
Definition: date.h:2929
sys_time_point to_timePoint(double d)
Convert a double to a sys_time_point assuming the double is in units of seconds.
size_t getWeekNum(sys_time_point tp)
Returns the weeknum of the selected timepoint as an unsigned integer.
double to_double(sys_time_point tp)
Convert a sys_time_point to a double. The double is returned in units of seconds.
sys_time_point sys_time_now()
Returns the current time as a sys_time_point (i.e. a std::chrono::time_point with microseconds precis...
time_stamp getTimeStampFromTimePoint(sys_time_point tp)
Return a time_stamp instance converted from the passed sys_time_point.
std::chrono::time_point< std::chrono::system_clock, std::chrono::microseconds > sys_time_point
This is a typedef for a custom system_clock time_point with microseconds precision.
value_type parser_Binom(const value_type &v1, const value_type &v2)
Function representing the binomial coefficient.
value_type parser_Faculty(const value_type &v)
Function representing the faculty of any natural number.
value_type parser_Parsec(const value_type &v)
Conversion function for 1pc.
value_type parser_gcd(const value_type &n, const value_type &k)
This function returns the greatest common divisor of both argments.
value_type parser_Norm(const value_type *vElements, int nElements)
This function calculates the vector norm of the elements in the passed array.
value_type parser_Pct(const value_type *vElements, int nElements)
This function calculates the selected percentile of the passed array.
value_type parser_is_string(const value_type &v)
This function is a numerical version of the string is_string() function. Used as a fallback.
value_type parser_studentFactor(const value_type &vFreedoms, const value_type &vAlpha)
This function returns the Student factor s_t for the selected degrees of freedom and a confidence int...
value_type parser_and(const value_type *vElements, int nElements)
This function calculates the logical AND operation between all elements in the passed array.
value_type parser_interval(const value_type &v, const value_type &vLeft, const value_type &vRight)
This function numerically defines a valid value range (the value is set to NaN, if outside of this ra...
value_type parser_Poise(const value_type &v)
Conversion function for 1Ps.
value_type parser_clock()
This function returns the current CPU clock count.
value_type parser_asec(const value_type &x)
This function returns the inverse secant of the passed value.
value_type parser_SphericalNeumann(const value_type &vn, const value_type &vc)
This function calculates the spherical von Neumann function.
string sErrorToken
value_type parser_theta(const value_type &x, const value_type &y, const value_type &z)
This function calculates the angle of a vector and the z axis in any z-r plane (the polar angle theta...
value_type parser_Lightyear(const value_type &v)
Conversion function for 1ly.
value_type * parser_AddVariable(const char_type *a_szName, void *a_pUserData)
This function represents the numerical variable factory. New memory is allocated in this function and...
value_type parser_SinusCardinalis(const value_type &v)
This function calculates the cardinal sine of x.
value_type parser_Barn(const value_type &v)
Conversion function for 1bn.
value_type parser_Yard(const value_type &v)
Conversion function for 1yd.
value_type parser_mol(const value_type &v)
Conversion function for 1mol.
value_type parser_csch(const value_type &x)
This function returns the hyperbolic cosecant of the passed value.
value_type parser_EllipticD(const value_type &phi, const value_type &n, const value_type &k)
This function returns the value of the elliptic intergal D(phi,n,k).
value_type parser_AiryA(const value_type &x)
This function calculates the Airy function Ai(x).
value_type parser_Nano(const value_type &a_fVal)
Conversion function for 1n.
static double ek(int k, int N)
Calculates the sum of binomial coefficients from k to N.
value_type parser_roof(const value_type &x)
This is the roof (ceil) function.
value_type parser_Zernike(const value_type &vn, const value_type &vm, const value_type &rho, const value_type &phi)
This function calculates the selected Zernike polynomials.
value_type parser_AssociatedLegendrePolynomial(const value_type &vl, const value_type &vm, const value_type &v)
This function calculates the associated Legendre polynomials of the selected order.
int nErrorIndices[2]
value_type parser_EllipticF(const value_type &phic, const value_type &kc)
This function returns the value of the elliptic intergal F(phi,k).
value_type parser_Micro(const value_type &a_fVal)
Conversion function for 1mu.
value_type parser_AssociatedLaguerrePolynomial(const value_type &vn, const value_type &vk, const value_type &v)
This function calculates the associated Laguerre polynomials of the selected order.
value_type parser_Ignore(const value_type &v)
Identity function. Used for ignoring functions and parameters in special cases.
value_type parser_Mile(const value_type &v)
Conversion function for 1mi.
value_type parser_Min(const value_type *vElements, int nElements)
This function calculates the minimal value of all elements in the passed array.
value_type parser_real(const value_type &v)
Extracts the real part of a complex number.
value_type parser_acsc(const value_type &x)
This function returns the inverse cosecant of the passed value.
value_type parser_beta(const value_type &a, const value_type &b)
This function returns the value of the Beta function.
value_type parser_complex(const value_type &re, const value_type &im)
Construct a complex number from two real numbers.
value_type parser_isnan(const value_type &v)
Returns, whether the selected value is NaN.
value_type parser_erf(const value_type &x)
This function calculates the gaussian error function.
value_type parser_date(const value_type &vTime, const value_type &vType)
This function converts UNIX time values into a selected part of a time stamp.
value_type parser_polar2rect(const value_type &v)
Converts a polar representation into a rectangular representation and returns it as a new complex num...
value_type parser_AstroUnit(const value_type &v)
Conversion function for 1AU.
value_type parser_LaguerrePolynomial(const value_type &vn, const value_type &v)
This function calculates the Laguerre polynomials of the selected order.
value_type parser_imSphericalHarmonics(const value_type &vl, const value_type &vm, const value_type &theta, const value_type &phi)
This function calculates the imaginary part of the selected spherical harmonics.
value_type parser_RegularCylBessel(const value_type &n, const value_type &x)
This function calculates the regulary bessel function.
value_type parser_time()
This function returns the current UNIX time.
value_type parser_rect(const value_type &x, const value_type &x0, const value_type &x1)
This is the rect function.
value_type parser_Not(const value_type &v)
Function representing the logical NOT operator.
time_t tTimeZero
Definition: kernel.cpp:43
value_type parser_Cnt(const value_type *vElements, int nElements)
This functioon simply returns the number of elements in its array (even the invalid ones).
value_type parser_PSI(const value_type &v)
Conversion function for 1psi.
value_type parser_sec(const value_type &x)
This function returns the secant of the passed value.
value_type parser_Milli(const value_type &a_fVal)
Conversion function for 1m.
value_type parser_Mega(const value_type &a_fVal)
Conversion function for 1M.
value_type parser_Num(const value_type *vElements, int nElements)
This function returns the number of valid elements in its array.
value_type parser_EllipticP(const value_type &phi, const value_type &n, const value_type &k)
This function returns the value of the elliptic intergal Pi(phi,n,k).
value_type parser_kmh(const value_type &v)
Conversion function for 1kmh.
value_type parser_zeta(const value_type &s)
This function returns the value of the Zeta function.
value_type parser_Giga(const value_type &a_fVal)
Conversion function for 1G.
value_type parser_SphericalBessel(const value_type &vn, const value_type &vc)
This function calculates the spherical bessel function.
value_type parser_gamma(const value_type &x)
This function calculates the riemannian Gamma function.
volatile sig_atomic_t exitsignal
value_type parser_ZernikeRadial(int n, int m, const value_type &rho)
This function calculates the radial part of the Zernike polynomials.
value_type parser_EllipticE(const value_type &phic, const value_type &kc)
This function returns the value of the elliptic intergal E(phi,k).
value_type parser_BetheWeizsaecker(const value_type &vN, const value_type &vZ)
This function calculates the nucleic core binding energy according the Bethe Weizsäcker formula.
value_type parser_Calorie(const value_type &v)
Conversion function for 1cal.
value_type parser_toDegree(const value_type &v)
This function converts radian to degree.
value_type parser_MaxPos(const value_type *vElements, int nElements)
This function returns the index of the (first) maximal value in the array.
value_type parser_sech(const value_type &x)
This function returns the hyperbolic secant of the passed value.
value_type parser_Torr(const value_type &v)
Conversion function for 1Torr/1mmhg.
value_type parser_Curie(const value_type &v)
Conversion function for 1C.
value_type parser_perlin(const value_type *vElements, int nElements)
This function implements the perlin noise function.
value_type parser_lcm(const value_type &n, const value_type &k)
This function returns the least common multiple of both arguments.
value_type parser_weeknum(const value_type &vTime)
This function returns the calendar week associated with the passed time value.
value_type parser_liter(const value_type &v)
Conversion function for 1l.
value_type parser_BinAND(const value_type &v1, const value_type &v2)
This function represents the binary AND operator.
value_type parser_round(const value_type &vToRound, const value_type &vDecimals)
This function rounds the passed value to the selected number of decimals.
value_type parser_log_b(const value_type &b, const value_type &x)
Calculates the logarithm of x using the base b.
value_type parser_SphericalHarmonics(const value_type &vl, const value_type &vm, const value_type &theta, const value_type &phi)
This function calculates the real part of the selected spherical harmonics.
value_type parser_Std(const value_type *vElements, int nElements)
This function calculates the standard deviation of the elements in the passed array.
value_type parser_Med(const value_type *vElements, int nElements)
This function calculates the median of the elements in the passed array.
value_type parser_digamma(const value_type &x)
This function returns the value of the Digamma function.
value_type parser_HermitePolynomial(const value_type &vn, const value_type &v)
This function calculates the Hermite polynomials of the selected order.
value_type parser_toRadian(const value_type &v)
This function converts degree to radian.
value_type parser_compare(const value_type *vElements, int nElements)
This function searches for elements of a specified type in the passed array.
value_type parser_Max(const value_type *vElements, int nElements)
This function calculates the maximal value of all elements in the passed array.
value_type parser_ivl(const value_type &x, const value_type &x0, const value_type &x1, const value_type &lborder, const value_type &rborder)
This function describes an interval with borders of a selected type (including, excluding,...
value_type parser_Mod(const value_type &v1, const value_type &v2)
This function represents the Modulo operator.
value_type parser_Avg(const value_type *vElements, int nElements)
This function calculates the average of all elements in passed array.
value_type parser_Angstroem(const value_type &v)
Conversion function for 1A.
value_type parser_dilogarithm(const value_type &x)
This function returns the value of the Dilogarithm Li2(x).
value_type parser_Random(const value_type &vRandMin, const value_type &vRandMax)
This function returns a uniformly distributed random number between both boundaries.
value_type parser_MinPos(const value_type *vElements, int nElements)
This function returns the index of the (first) minimal value in the array.
value_type parser_Kilo(const value_type &a_fVal)
Conversion function for 1k.
value_type parser_LegendrePolynomial(const value_type &vn, const value_type &v)
This function calculates the Legendre polynomials of the selected order.
value_type parser_gRandom(const value_type &vRandAvg, const value_type &vRandstd)
This function returns a gaussian distributed random number using the passed values as mean and standa...
value_type parser_Gauss(const value_type &v)
Conversion function for 1Gs.
value_type parser_polynomial(const value_type *vElements, int nElements)
This function implements an abstract polynomial of an arbitrary order.
value_type parser_imag(const value_type &v)
Extracts the imaginary part of a complex number.
value_type parser_xor(const value_type *vElements, int nElements)
This function calculates the logical XOR operation between all elements in the passed array.
value_type parser_acsch(const value_type &x)
This function returns the inverse hyperbolic cosecant of the passed value.
value_type parser_Fahrenheit(const value_type &v)
Conversion function for 1°F.
value_type parser_BinOR(const value_type &v1, const value_type &v2)
This function represents the binary OR operator.
value_type parser_Fermi(const value_type &v)
Conversion function for 1fm.
value_type parser_imaginaryUnit(const value_type &v)
Multiplies a number with the imaginary unit.
value_type parser_ElectronVolt(const value_type &v)
Conversion function for 1eV.
value_type parser_Inch(const value_type &v)
Conversion function for 1in.
value_type parser_cot(const value_type &x)
This function returns the cotangent of the passed value.
value_type parser_Sum(const value_type *vElements, int nElements)
This function summarizes all elements in the passed array.
value_type parser_erfc(const value_type &x)
This function calculates the complementary gaussian error function.
value_type parser_Foot(const value_type &v)
Conversion function for 1ft.
value_type parser_or(const value_type *vElements, int nElements)
This function calculates the logical OR operation between all elements in the passed array.
value_type parser_numereversion()
Returns the version number of NumeRe as a natural number.
value_type parser_doubleFaculty(const value_type &v)
Function representing the double faculty of any natural number.
value_type parser_Knoten(const value_type &v)
Conversion function for 1kn.
value_type parser_floor(const value_type &x)
This is the floor function.
value_type parser_sleep(const value_type &milliseconds)
Sleeps for the passed amount of milliseconds and returns this number.
value_type parser_csc(const value_type &x)
This function returns the cosecant of the passed value.
value_type parser_clausen(const value_type &x)
This function returns the value of the Clausen function.
value_type parser_phi(const value_type &x, const value_type &y)
This function calculates the angle of a vector and the x axis in the x-y plane (the azimuthal angle p...
value_type parser_asech(const value_type &x)
This function returns the inverse hyperbolic secant of the passed value.
value_type parser_Heaviside(const value_type &v)
This function represents the Heaviside (theta) function.
value_type parser_IrregularCylBessel(const value_type &n, const value_type &x)
This function calculates the irregulary bessel (von Neumann) function.
value_type parser_polygamma(const value_type &n, const value_type &x)
This function returns the value if the Polygamma function.
value_type parser_conj(const value_type &v)
Calculates the complex conjugate number of the passed complex number.
value_type parser_product(const value_type *vElements, int nElements)
This function calculates the product of all elements in the passed array.
static std::complex< double > complex_zeta(const std::complex< double > &s)
Calculates the complex-valued Riemannian Zeta function for complex numbers with Re(s) >= 0.
value_type parser_mph(const value_type &v)
Conversion function for 1mph.
value_type parser_rect2polar(const value_type &v)
Converts a rectangular representation into polar representation and returns it as a new complex numbe...
value_type parser_XOR(const value_type &v1, const value_type &v2)
This function represent the XOR operator.
value_type parser_AiryB(const value_type &x)
This function calculates the Airy function Bi(x).
value_type parser_Celsius(const value_type &v)
Conversion function for 1°C.
std::mt19937 & getRandGenInstance()
Returns a reference to the central random number generator instance, which is globally accessible by ...
Definition: tools.cpp:91
std::complex< double > intPower(const std::complex< double > &, int)
This function calculates the power of a value with the specialization that the exponent is an integer...
Definition: tools.cpp:3640
static const long MINOR
Definition: version.h:18
static const long BUILD
Definition: version.h:19
static const long MAJOR
Definition: version.h:17
static const char UBUNTU_VERSION_STYLE[]
Definition: version.h:10
CONSTCD14 To round(const std::chrono::duration< Rep, Period > &d)
Definition: date.h:1278
CONSTCD14 std::enable_if< detail::no_overflow< Period, typenameTo::period >::value, To >::type floor(const std::chrono::duration< Rep, Period > &d)
Definition: date.h:1251
CONSTCD11 std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Definition: date.h:1317
CONSTCD14 To ceil(const std::chrono::duration< Rep, Period > &d)
Definition: date.h:1302
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
bool isnan(const value_type &v)
Definition: muParserDef.h:379
std::vector< double > real(const std::vector< value_type > &vVec)
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:263
bool isinf(const value_type &v)
Definition: muParserDef.h:374
value_type rint(value_type v)
#define min(a, b)
Definition: resampler.cpp:34
#define M_PI
Definition: resampler.cpp:47
#define max(a, b)
Definition: resampler.cpp:30
This structure defines all fields necessary to create a time stamp or a formatted date.
date::year_month_day m_ymd
std::chrono::microseconds m_microsecs
std::chrono::minutes m_minutes
std::chrono::seconds m_seconds
std::chrono::hours m_hours
std::chrono::milliseconds m_millisecs
long long int intCast(const std::complex< double > &)
Casts the real part of the complex number to an integer and avoids rounding errors.
Definition: tools.cpp:1824
double student_t(int nFreedoms, double dConfidenceInterval)
Calculate the student_t value for the selected degrees of freedoms and the desired confidence interva...
Definition: student_t.cpp:35