File indexing completed on 2024-05-12 17:22:37
0001 // This file is part of the SpeedCrunch project 0002 // Copyright (C) 2004-2006 Ariya Hidayat <ariya@kde.org> 0003 // Copyright (C) 2007, 2009 Wolf Lammen 0004 // Copyright (C) 2007-2009, 2013, 2014 @heldercorreia 0005 // Copyright (C) 2009 Andreas Scherer <andreas_coder@freenet.de> 0006 // Copyright (C) 2011 Enrico Rós <enrico.ros@gmail.com> 0007 // 0008 // This program is free software; you can redistribute it and/or 0009 // modify it under the terms of the GNU General Public License 0010 // as published by the Free Software Foundation; either version 2 0011 // of the License, or (at your option) any later version. 0012 // 0013 // This program is distributed in the hope that it will be useful, 0014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0016 // GNU General Public License for more details. 0017 // 0018 // You should have received a copy of the GNU General Public License 0019 // along with this program; see the file COPYING. If not, write to 0020 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 // Boston, MA 02110-1301, USA. 0022 0023 #include "functions.h" 0024 0025 #include "settings.h" 0026 #include "hmath.h" 0027 #include "cmath.h" 0028 0029 #include <KLocalizedString> 0030 0031 #include <QCoreApplication> 0032 #include <QHash> 0033 0034 #include <algorithm> 0035 #include <functional> 0036 #include <cfloat> 0037 #include <cmath> 0038 #include <numeric> 0039 0040 #define FUNCTION_INSERT(ID) insert(new Function(#ID, function_ ## ID, this)) 0041 #define FUNCTION_USAGE(ID, USAGE) find(#ID)->setUsage(QString::fromLatin1(USAGE)); 0042 #define FUNCTION_USAGE_i18n(ID, USAGE) find(#ID)->setUsage(USAGE); 0043 #define FUNCTION_NAME(ID, NAME) find(#ID)->setName(NAME) 0044 0045 #define ENSURE_MINIMUM_ARGUMENT_COUNT(i) \ 0046 if (args.count() < i) { \ 0047 f->setError(InvalidParamCount); \ 0048 return CMath::nan(InvalidParamCount); \ 0049 } 0050 0051 #define ENSURE_ARGUMENT_COUNT(i) \ 0052 if (args.count() != (i)) { \ 0053 f->setError(InvalidParamCount); \ 0054 return CMath::nan(InvalidParamCount); \ 0055 } 0056 0057 #define ENSURE_EITHER_ARGUMENT_COUNT(i, j) \ 0058 if (args.count() != (i) && args.count() != (j)) { \ 0059 f->setError(InvalidParamCount); \ 0060 return CMath::nan(InvalidParamCount); \ 0061 } 0062 0063 #define ENSURE_SAME_DIMENSION() \ 0064 for(int i=0; i<args.count()-1; ++i) { \ 0065 if(!args.at(i).sameDimension(args.at((i)+1))) \ 0066 return DMath::nan(InvalidDimension);\ 0067 } 0068 0069 #define ENSURE_REAL_ARGUMENT(i) \ 0070 if (!args[i].isReal()) { \ 0071 f->setError(OutOfDomain); \ 0072 return CMath::nan(); \ 0073 } 0074 0075 #define ENSURE_REAL_ARGUMENTS() \ 0076 for (int i = 0; i < args.count(); i++) { \ 0077 ENSURE_REAL_ARGUMENT(i); \ 0078 } 0079 0080 #define CONVERT_ARGUMENT_ANGLE(angle) \ 0081 if (Settings::instance()->angleUnit == 'd') { \ 0082 if (angle.isReal()) \ 0083 angle = DMath::deg2rad(angle); \ 0084 else { \ 0085 f->setError(OutOfDomain); \ 0086 return DMath::nan(); \ 0087 } \ 0088 } \ 0089 else if (Settings::instance()->angleUnit == 'g') { \ 0090 if (angle.isReal()) \ 0091 angle = DMath::gon2rad(angle); \ 0092 else { \ 0093 f->setError(OutOfDomain); \ 0094 return DMath::nan(); \ 0095 } \ 0096 } 0097 0098 #define CONVERT_RESULT_ANGLE(result) \ 0099 if (Settings::instance()->angleUnit == 'd') \ 0100 result = DMath::rad2deg(result); \ 0101 else if (Settings::instance()->angleUnit == 'g') \ 0102 result = DMath::rad2gon(result); 0103 0104 static FunctionRepo* s_FunctionRepoInstance = 0; 0105 0106 // FIXME: destructor seems not to be called 0107 static void s_deleteFunctions() 0108 { 0109 delete s_FunctionRepoInstance; 0110 } 0111 0112 Quantity Function::exec(const Function::ArgumentList& args) 0113 { 0114 if (!m_ptr) 0115 return CMath::nan(); 0116 setError(Success); 0117 Quantity result = (*m_ptr)(this, args); 0118 if(result.error()) 0119 setError(result.error()); 0120 return result; 0121 } 0122 0123 Quantity function_abs(Function* f, const Function::ArgumentList& args) 0124 { 0125 ENSURE_ARGUMENT_COUNT(1); 0126 return DMath::abs(args.at(0)); 0127 } 0128 0129 Quantity function_average(Function* f, const Function::ArgumentList& args) 0130 { 0131 /* TODO : complex mode switch for this function */ 0132 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0133 return std::accumulate(args.begin()+1, args.end(), *args.begin()) / Quantity(args.count()); 0134 } 0135 0136 Quantity function_absdev(Function* f, const Function::ArgumentList& args) 0137 { 0138 /* TODO : complex mode switch for this function */ 0139 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0140 Quantity mean = function_average(f, args); 0141 if (mean.isNan()) 0142 return mean; // pass the error along 0143 Quantity acc = 0; 0144 for (int i = 0; i < args.count(); ++i) 0145 acc += DMath::abs(args.at(i) - mean); 0146 return acc / Quantity(args.count()); 0147 } 0148 0149 Quantity function_int(Function* f, const Function::ArgumentList& args) 0150 { 0151 /* TODO : complex mode switch for this function */ 0152 ENSURE_ARGUMENT_COUNT(1); 0153 return DMath::integer(args[0]); 0154 } 0155 0156 Quantity function_trunc(Function* f, const Function::ArgumentList& args) 0157 { 0158 /* TODO : complex mode switch for this function */ 0159 ENSURE_EITHER_ARGUMENT_COUNT(1, 2); 0160 Quantity num = args.at(0); 0161 if (args.count() == 2) { 0162 Quantity argprec = args.at(1); 0163 if (argprec != 0) { 0164 if (!argprec.isInteger()) { 0165 f->setError(OutOfDomain); 0166 return DMath::nan(); 0167 } 0168 int prec = argprec.numericValue().toInt(); 0169 if (prec) 0170 return DMath::trunc(num, prec); 0171 // The second parameter exceeds the integer limits. 0172 if (argprec < 0) 0173 return Quantity(0); 0174 return num; 0175 } 0176 } 0177 return DMath::trunc(num); 0178 } 0179 0180 Quantity function_frac(Function* f, const Function::ArgumentList& args) 0181 { 0182 ENSURE_ARGUMENT_COUNT(1); 0183 return DMath::frac(args[0]); 0184 } 0185 0186 Quantity function_floor(Function* f, const Function::ArgumentList& args) 0187 { 0188 ENSURE_ARGUMENT_COUNT(1); 0189 return DMath::floor(args[0]); 0190 } 0191 0192 Quantity function_ceil(Function* f, const Function::ArgumentList& args) 0193 { 0194 ENSURE_ARGUMENT_COUNT(1); 0195 return DMath::ceil(args[0]); 0196 } 0197 0198 Quantity function_gcd(Function* f, const Function::ArgumentList& args) 0199 { 0200 /* TODO : complex mode switch for this function */ 0201 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0202 for (int i = 0; i < args.count(); ++i) 0203 if (!args[i].isInteger()) { 0204 f->setError(OutOfDomain); 0205 return DMath::nan(); 0206 } 0207 return std::accumulate(args.begin() + 1, args.end(), args.at(0), DMath::gcd); 0208 } 0209 0210 Quantity function_round(Function* f, const Function::ArgumentList& args) 0211 { 0212 /* TODO : complex mode switch for this function */ 0213 ENSURE_EITHER_ARGUMENT_COUNT(1, 2); 0214 Quantity num = args.at(0); 0215 if (args.count() == 2) { 0216 Quantity argPrecision = args.at(1); 0217 if (argPrecision != 0) { 0218 if (!argPrecision.isInteger()) { 0219 f->setError(OutOfDomain); 0220 return DMath::nan(); 0221 } 0222 int prec = argPrecision.numericValue().toInt(); 0223 if (prec) 0224 return DMath::round(num, prec); 0225 // The second parameter exceeds the integer limits. 0226 if (argPrecision < 0) 0227 return Quantity(0); 0228 return num; 0229 } 0230 } 0231 return DMath::round(num); 0232 } 0233 0234 Quantity function_sqrt(Function* f, const Function::ArgumentList& args) 0235 { 0236 ENSURE_ARGUMENT_COUNT(1); 0237 return DMath::sqrt(args[0]); 0238 } 0239 0240 Quantity function_variance(Function* f, const Function::ArgumentList& args) 0241 { 0242 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0243 0244 Quantity mean = function_average(f, args); 0245 if (mean.isNan()) 0246 return mean; 0247 0248 Quantity acc(DMath::real(args[0] - mean)*DMath::real(args[0] - mean) 0249 + DMath::imag(args[0] - mean)*DMath::imag(args[0] - mean)); 0250 for (int i = 1; i < args.count(); ++i) { 0251 Quantity q(args[i] - mean); 0252 acc += DMath::real(q)*DMath::real(q) + DMath::imag(q)*DMath::imag(q); 0253 } 0254 0255 return acc / Quantity(args.count()); 0256 } 0257 0258 Quantity function_stddev(Function* f, const Function::ArgumentList& args) 0259 { 0260 /* TODO : complex mode switch for this function */ 0261 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0262 return DMath::sqrt(function_variance(f, args)); 0263 } 0264 0265 Quantity function_cbrt(Function* f, const Function::ArgumentList& args) 0266 { 0267 ENSURE_ARGUMENT_COUNT(1); 0268 return DMath::cbrt(args[0]); 0269 } 0270 0271 Quantity function_exp(Function* f, const Function::ArgumentList& args) 0272 { 0273 ENSURE_ARGUMENT_COUNT(1); 0274 return DMath::exp(args[0]); 0275 } 0276 0277 Quantity function_ln(Function* f, const Function::ArgumentList& args) 0278 { 0279 ENSURE_ARGUMENT_COUNT(1); 0280 return DMath::ln(args[0]); 0281 } 0282 0283 Quantity function_lg(Function* f, const Function::ArgumentList& args) 0284 { 0285 ENSURE_ARGUMENT_COUNT(1); 0286 return DMath::lg(args[0]); 0287 } 0288 0289 Quantity function_lb(Function* f, const Function::ArgumentList& args) 0290 { 0291 ENSURE_ARGUMENT_COUNT(1); 0292 return DMath::lb(args[0]); 0293 } 0294 0295 Quantity function_log(Function* f, const Function::ArgumentList& args) 0296 { 0297 /* TODO : complex mode switch for this function */ 0298 ENSURE_ARGUMENT_COUNT(2); 0299 return DMath::log(args.at(0), args.at(1)); 0300 } 0301 0302 Quantity function_real(Function* f, const Function::ArgumentList& args) 0303 { 0304 ENSURE_ARGUMENT_COUNT(1); 0305 return DMath::real(args.at(0)); 0306 } 0307 0308 Quantity function_imag(Function* f, const Function::ArgumentList& args) 0309 { 0310 ENSURE_ARGUMENT_COUNT(1); 0311 return DMath::imag(args.at(0)); 0312 } 0313 0314 Quantity function_conj(Function* f, const Function::ArgumentList& args) 0315 { 0316 ENSURE_ARGUMENT_COUNT(1); 0317 return DMath::conj(args.at(0)); 0318 } 0319 0320 Quantity function_phase(Function* f, const Function::ArgumentList& args) 0321 { 0322 ENSURE_ARGUMENT_COUNT(1); 0323 Quantity angle = DMath::phase(args.at(0)); 0324 CONVERT_RESULT_ANGLE(angle); 0325 return angle; 0326 } 0327 0328 0329 Quantity function_sin(Function* f, const Function::ArgumentList& args) 0330 { 0331 ENSURE_ARGUMENT_COUNT(1); 0332 Quantity angle = args.at(0); 0333 CONVERT_ARGUMENT_ANGLE(angle); 0334 return DMath::sin(angle); 0335 } 0336 0337 Quantity function_cos(Function* f, const Function::ArgumentList& args) 0338 { 0339 ENSURE_ARGUMENT_COUNT(1); 0340 Quantity angle = args.at(0); 0341 CONVERT_ARGUMENT_ANGLE(angle); 0342 return DMath::cos(angle); 0343 } 0344 0345 Quantity function_tan(Function* f, const Function::ArgumentList& args) 0346 { 0347 ENSURE_ARGUMENT_COUNT(1); 0348 Quantity angle = args.at(0); 0349 CONVERT_ARGUMENT_ANGLE(angle); 0350 return DMath::tan(angle); 0351 } 0352 0353 Quantity function_cot(Function* f, const Function::ArgumentList& args) 0354 { 0355 ENSURE_ARGUMENT_COUNT(1); 0356 Quantity angle = args.at(0); 0357 CONVERT_ARGUMENT_ANGLE(angle); 0358 return DMath::cot(angle); 0359 } 0360 0361 Quantity function_sec(Function* f, const Function::ArgumentList& args) 0362 { 0363 ENSURE_ARGUMENT_COUNT(1); 0364 Quantity angle = args.at(0); 0365 CONVERT_ARGUMENT_ANGLE(angle); 0366 return DMath::sec(angle); 0367 } 0368 0369 Quantity function_csc(Function* f, const Function::ArgumentList& args) 0370 { 0371 ENSURE_ARGUMENT_COUNT(1); 0372 Quantity angle = args.at(0); 0373 CONVERT_ARGUMENT_ANGLE(angle); 0374 return DMath::csc(angle); 0375 } 0376 0377 Quantity function_arcsin(Function* f, const Function::ArgumentList& args) 0378 { 0379 ENSURE_ARGUMENT_COUNT(1); 0380 Quantity result; 0381 result = DMath::arcsin(args.at(0)); 0382 CONVERT_RESULT_ANGLE(result); 0383 return result; 0384 } 0385 0386 Quantity function_arccos(Function* f, const Function::ArgumentList& args) 0387 { 0388 ENSURE_ARGUMENT_COUNT(1); 0389 Quantity result; 0390 result = DMath::arccos(args.at(0)); 0391 CONVERT_RESULT_ANGLE(result); 0392 return result; 0393 } 0394 0395 Quantity function_arctan(Function* f, const Function::ArgumentList& args) 0396 { 0397 ENSURE_ARGUMENT_COUNT(1); 0398 Quantity result; 0399 result = DMath::arctan(args.at(0)); 0400 CONVERT_RESULT_ANGLE(result); 0401 return result; 0402 } 0403 0404 Quantity function_arctan2(Function* f, const Function::ArgumentList& args) 0405 { 0406 ENSURE_ARGUMENT_COUNT(2); 0407 Quantity result; 0408 result = DMath::arctan2(args.at(0), args.at(1)); 0409 CONVERT_RESULT_ANGLE(result); 0410 return result; 0411 } 0412 0413 Quantity function_sinh(Function* f, const Function::ArgumentList& args) 0414 { 0415 ENSURE_ARGUMENT_COUNT(1); 0416 return DMath::sinh(args[0]); 0417 } 0418 0419 Quantity function_cosh(Function* f, const Function::ArgumentList& args) 0420 { 0421 ENSURE_ARGUMENT_COUNT(1); 0422 return DMath::cosh(args[0]); 0423 } 0424 0425 Quantity function_tanh(Function* f, const Function::ArgumentList& args) 0426 { 0427 ENSURE_ARGUMENT_COUNT(1); 0428 return DMath::tanh(args[0]); 0429 } 0430 0431 Quantity function_arsinh(Function* f, const Function::ArgumentList& args) 0432 { 0433 ENSURE_ARGUMENT_COUNT(1); 0434 return DMath::arsinh(args[0]); 0435 } 0436 0437 Quantity function_arcosh(Function* f, const Function::ArgumentList& args) 0438 { 0439 ENSURE_ARGUMENT_COUNT(1); 0440 return DMath::arcosh(args[0]); 0441 } 0442 0443 Quantity function_artanh(Function* f, const Function::ArgumentList& args) 0444 { 0445 ENSURE_ARGUMENT_COUNT(1); 0446 return DMath::artanh(args[0]); 0447 } 0448 0449 Quantity function_erf(Function* f, const Function::ArgumentList& args) 0450 { 0451 ENSURE_ARGUMENT_COUNT(1); 0452 return DMath::erf(args[0]); 0453 } 0454 0455 Quantity function_erfc(Function* f, const Function::ArgumentList& args) 0456 { 0457 ENSURE_ARGUMENT_COUNT(1); 0458 return DMath::erfc(args[0]); 0459 } 0460 0461 Quantity function_gamma(Function* f, const Function::ArgumentList& args) 0462 { 0463 ENSURE_ARGUMENT_COUNT(1); 0464 return DMath::gamma(args[0]); 0465 } 0466 0467 Quantity function_lngamma(Function* f, const Function::ArgumentList& args) 0468 { 0469 ENSURE_ARGUMENT_COUNT(1); 0470 ENSURE_REAL_ARGUMENT(0); 0471 return DMath::lnGamma(args[0]); 0472 } 0473 0474 Quantity function_sgn(Function* f, const Function::ArgumentList& args) 0475 { 0476 ENSURE_ARGUMENT_COUNT(1); 0477 return DMath::sgn(args[0]); 0478 } 0479 0480 Quantity function_ncr(Function* f, const Function::ArgumentList& args) 0481 { 0482 /* TODO : complex mode switch for this function */ 0483 ENSURE_ARGUMENT_COUNT(2); 0484 return DMath::nCr(args.at(0), args.at(1)); 0485 } 0486 0487 Quantity function_npr(Function* f, const Function::ArgumentList& args) 0488 { 0489 /* TODO : complex mode switch for this function */ 0490 ENSURE_ARGUMENT_COUNT(2); 0491 return DMath::nPr(args.at(0), args.at(1)); 0492 } 0493 0494 Quantity function_degrees(Function* f, const Function::ArgumentList& args) 0495 { 0496 ENSURE_ARGUMENT_COUNT(1); 0497 return DMath::rad2deg(args[0]); 0498 } 0499 0500 Quantity function_radians(Function* f, const Function::ArgumentList& args) 0501 { 0502 ENSURE_ARGUMENT_COUNT(1); 0503 return DMath::deg2rad(args[0]); 0504 } 0505 0506 Quantity function_gradians(Function* f, const Function::ArgumentList& args) 0507 { 0508 ENSURE_ARGUMENT_COUNT(1); 0509 return DMath::rad2gon(args[0]); 0510 } 0511 0512 Quantity function_max(Function* f, const Function::ArgumentList& args) 0513 { 0514 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0515 ENSURE_REAL_ARGUMENTS() 0516 ENSURE_SAME_DIMENSION() 0517 return *std::max_element(args.begin(), args.end()); 0518 } 0519 0520 Quantity function_median(Function* f, const Function::ArgumentList& args) 0521 { 0522 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0523 ENSURE_REAL_ARGUMENTS() 0524 ENSURE_SAME_DIMENSION() 0525 0526 Function::ArgumentList sortedArgs = args; 0527 std::sort(sortedArgs.begin(), sortedArgs.end()); 0528 0529 if ((args.count() & 1) == 1) 0530 return sortedArgs.at((args.count() - 1) / 2); 0531 0532 const int centerLeft = args.count() / 2 - 1; 0533 return (sortedArgs.at(centerLeft) + sortedArgs.at(centerLeft + 1)) / Quantity(2); 0534 } 0535 0536 Quantity function_min(Function* f, const Function::ArgumentList& args) 0537 { 0538 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0539 ENSURE_REAL_ARGUMENTS() 0540 ENSURE_SAME_DIMENSION() 0541 return *std::min_element(args.begin(), args.end()); 0542 } 0543 0544 Quantity function_sum(Function* f, const Function::ArgumentList& args) 0545 { 0546 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0547 return std::accumulate(args.begin(), args.end(), Quantity(0)); 0548 } 0549 0550 Quantity function_product(Function* f, const Function::ArgumentList& args) 0551 { 0552 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0553 return std::accumulate(args.begin(), args.end(), Quantity(1), std::multiplies<Quantity>()); 0554 } 0555 0556 Quantity function_geomean(Function* f, const Function::ArgumentList& args) 0557 { 0558 /* TODO : complex mode switch for this function */ 0559 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0560 0561 Quantity result = std::accumulate(args.begin(), args.end(), Quantity(1), 0562 std::multiplies<Quantity>()); 0563 0564 if (result <= Quantity(0)) 0565 return DMath::nan(OutOfDomain); 0566 0567 if (args.count() == 1) 0568 return result; 0569 0570 if (args.count() == 2) 0571 return DMath::sqrt(result); 0572 0573 return DMath::raise(result, Quantity(1)/Quantity(args.count())); 0574 } 0575 0576 Quantity function_dec(Function* f, const Function::ArgumentList& args) 0577 { 0578 ENSURE_ARGUMENT_COUNT(1); 0579 return Quantity(args.at(0)).setFormat(Quantity::Format::Decimal() + Quantity(args.at(0)).format()); 0580 } 0581 0582 Quantity function_hex(Function* f, const Function::ArgumentList& args) 0583 { 0584 ENSURE_ARGUMENT_COUNT(1); 0585 return Quantity(args.at(0)).setFormat(Quantity::Format::Fixed() + Quantity::Format::Hexadecimal() + Quantity(args.at(0)).format()); 0586 } 0587 0588 Quantity function_oct(Function* f, const Function::ArgumentList& args) 0589 { 0590 ENSURE_ARGUMENT_COUNT(1); 0591 return Quantity(args.at(0)).setFormat(Quantity::Format::Fixed() + Quantity::Format::Octal() + Quantity(args.at(0)).format()); 0592 } 0593 0594 Quantity function_bin(Function* f, const Function::ArgumentList& args) 0595 { 0596 ENSURE_ARGUMENT_COUNT(1); 0597 return Quantity(args.at(0)).setFormat(Quantity::Format::Fixed() + Quantity::Format::Binary() + Quantity(args.at(0)).format()); 0598 } 0599 0600 Quantity function_cart(Function* f, const Function::ArgumentList& args) 0601 { 0602 ENSURE_ARGUMENT_COUNT(1); 0603 return Quantity(args.at(0)).setFormat(Quantity::Format::Cartesian() + Quantity(args.at(0)).format()); 0604 } 0605 0606 Quantity function_polar(Function* f, const Function::ArgumentList& args) 0607 { 0608 ENSURE_ARGUMENT_COUNT(1); 0609 return Quantity(args.at(0)).setFormat(Quantity::Format::Polar() + Quantity(args.at(0)).format()); 0610 } 0611 0612 Quantity function_binompmf(Function* f, const Function::ArgumentList& args) 0613 { 0614 ENSURE_ARGUMENT_COUNT(3); 0615 return DMath::binomialPmf(args.at(0), args.at(1), args.at(2)); 0616 } 0617 0618 Quantity function_binomcdf(Function* f, const Function::ArgumentList& args) 0619 { 0620 /* TODO : complex mode switch for this function */ 0621 ENSURE_ARGUMENT_COUNT(3); 0622 return DMath::binomialCdf(args.at(0), args.at(1), args.at(2)); 0623 } 0624 0625 Quantity function_binommean(Function* f, const Function::ArgumentList& args) 0626 { 0627 /* TODO : complex mode switch for this function */ 0628 ENSURE_ARGUMENT_COUNT(2); 0629 return DMath::binomialMean(args.at(0), args.at(1)); 0630 } 0631 0632 Quantity function_binomvar(Function* f, const Function::ArgumentList& args) 0633 { 0634 /* TODO : complex mode switch for this function */ 0635 ENSURE_ARGUMENT_COUNT(2); 0636 return DMath::binomialVariance(args.at(0), args.at(1)); 0637 } 0638 0639 Quantity function_hyperpmf(Function* f, const Function::ArgumentList& args) 0640 { 0641 /* TODO : complex mode switch for this function */ 0642 ENSURE_ARGUMENT_COUNT(4); 0643 return DMath::hypergeometricPmf(args.at(0), args.at(1), args.at(2), args.at(3)); 0644 } 0645 0646 Quantity function_hypercdf(Function* f, const Function::ArgumentList& args) 0647 { 0648 /* TODO : complex mode switch for this function */ 0649 ENSURE_ARGUMENT_COUNT(4); 0650 return DMath::hypergeometricCdf(args.at(0), args.at(1), args.at(2), args.at(3)); 0651 } 0652 0653 Quantity function_hypermean(Function* f, const Function::ArgumentList& args) 0654 { 0655 /* TODO : complex mode switch for this function */ 0656 ENSURE_ARGUMENT_COUNT(3); 0657 return DMath::hypergeometricMean(args.at(0), args.at(1), args.at(2)); 0658 } 0659 0660 Quantity function_hypervar(Function* f, const Function::ArgumentList& args) 0661 { 0662 /* TODO : complex mode switch for this function */ 0663 ENSURE_ARGUMENT_COUNT(3); 0664 return DMath::hypergeometricVariance(args.at(0), args.at(1), args.at(2)); 0665 } 0666 0667 Quantity function_poipmf(Function* f, const Function::ArgumentList& args) 0668 { 0669 /* TODO : complex mode switch for this function */ 0670 ENSURE_ARGUMENT_COUNT(2); 0671 return DMath::poissonPmf(args.at(0), args.at(1)); 0672 } 0673 0674 Quantity function_poicdf(Function* f, const Function::ArgumentList& args) 0675 { 0676 /* TODO : complex mode switch for this function */ 0677 ENSURE_ARGUMENT_COUNT(2); 0678 return DMath::poissonCdf(args.at(0), args.at(1)); 0679 } 0680 0681 Quantity function_poimean(Function* f, const Function::ArgumentList& args) 0682 { 0683 /* TODO : complex mode switch for this function */ 0684 ENSURE_ARGUMENT_COUNT(1); 0685 return DMath::poissonMean(args.at(0)); 0686 } 0687 0688 Quantity function_poivar(Function* f, const Function::ArgumentList& args) 0689 { 0690 /* TODO : complex mode switch for this function */ 0691 ENSURE_ARGUMENT_COUNT(1); 0692 return DMath::poissonVariance(args.at(0)); 0693 } 0694 0695 Quantity function_mask(Function* f, const Function::ArgumentList& args) 0696 { 0697 /* TODO : complex mode switch for this function */ 0698 ENSURE_ARGUMENT_COUNT(2); 0699 return DMath::mask(args.at(0), args.at(1)); 0700 } 0701 0702 Quantity function_unmask(Function* f, const Function::ArgumentList& args) 0703 { 0704 /* TODO : complex mode switch for this function */ 0705 ENSURE_ARGUMENT_COUNT(2); 0706 return DMath::sgnext(args.at(0), args.at(1)); 0707 } 0708 0709 Quantity function_not(Function* f, const Function::ArgumentList& args) 0710 { 0711 /* TODO : complex mode switch for this function */ 0712 ENSURE_ARGUMENT_COUNT(1); 0713 return ~args.at(0); 0714 } 0715 0716 Quantity function_and(Function* f, const Function::ArgumentList& args) 0717 { 0718 /* TODO : complex mode switch for this function */ 0719 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0720 return std::accumulate(args.begin(), args.end(), Quantity(-1), 0721 std::mem_fun_ref(&Quantity::operator&)); 0722 } 0723 0724 Quantity function_or(Function* f, const Function::ArgumentList& args) 0725 { 0726 /* TODO : complex mode switch for this function */ 0727 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0728 return std::accumulate(args.begin(), args.end(), Quantity(0), 0729 std::mem_fun_ref(&Quantity::operator|)); 0730 } 0731 0732 Quantity function_xor(Function* f, const Function::ArgumentList& args) 0733 { 0734 /* TODO : complex mode switch for this function */ 0735 ENSURE_MINIMUM_ARGUMENT_COUNT(2); 0736 return std::accumulate(args.begin(), args.end(), Quantity(0), 0737 std::mem_fun_ref(&Quantity::operator^)); 0738 } 0739 0740 Quantity function_shl(Function* f, const Function::ArgumentList& args) 0741 { 0742 /* TODO : complex mode switch for this function */ 0743 ENSURE_ARGUMENT_COUNT(2); 0744 return DMath::ashr(args.at(0), -args.at(1)); 0745 } 0746 0747 Quantity function_shr(Function* f, const Function::ArgumentList& args) 0748 { 0749 /* TODO : complex mode switch for this function */ 0750 ENSURE_ARGUMENT_COUNT(2); 0751 return DMath::ashr(args.at(0), args.at(1)); 0752 } 0753 0754 Quantity function_idiv(Function* f, const Function::ArgumentList& args) 0755 { 0756 /* TODO : complex mode switch for this function */ 0757 ENSURE_ARGUMENT_COUNT(2); 0758 return DMath::idiv(args.at(0), args.at(1)); 0759 } 0760 0761 Quantity function_mod(Function* f, const Function::ArgumentList& args) 0762 { 0763 /* TODO : complex mode switch for this function */ 0764 ENSURE_ARGUMENT_COUNT(2); 0765 return args.at(0) % args.at(1); 0766 } 0767 0768 Quantity function_ieee754_decode(Function* f, const Function::ArgumentList& args) 0769 { 0770 /* TODO : complex mode switch for this function */ 0771 ENSURE_EITHER_ARGUMENT_COUNT(3, 4); 0772 if (args.count() == 3) { 0773 return DMath::decodeIeee754(args.at(0), args.at(1), args.at(2)); 0774 } else { 0775 return DMath::decodeIeee754(args.at(0), args.at(1), args.at(2), args.at(3)); 0776 } 0777 } 0778 0779 Quantity function_ieee754_encode(Function* f, const Function::ArgumentList& args) 0780 { 0781 /* TODO : complex mode switch for this function */ 0782 ENSURE_EITHER_ARGUMENT_COUNT(3, 4); 0783 if (args.count() == 3) { 0784 return DMath::encodeIeee754(args.at(0), args.at(1), args.at(2)); 0785 } else { 0786 return DMath::encodeIeee754(args.at(0), args.at(1), args.at(2), args.at(3)); 0787 } 0788 } 0789 0790 Quantity function_ieee754_half_decode(Function* f, const Function::ArgumentList& args) 0791 { 0792 /* TODO : complex mode switch for this function */ 0793 ENSURE_ARGUMENT_COUNT(1); 0794 return DMath::decodeIeee754(args.at(0), 5, 10); 0795 } 0796 0797 Quantity function_ieee754_half_encode(Function* f, const Function::ArgumentList& args) 0798 { 0799 /* TODO : complex mode switch for this function */ 0800 ENSURE_ARGUMENT_COUNT(1); 0801 return DMath::encodeIeee754(args.at(0), 5, 10); 0802 } 0803 0804 Quantity function_ieee754_single_decode(Function* f, const Function::ArgumentList& args) 0805 { 0806 /* TODO : complex mode switch for this function */ 0807 ENSURE_ARGUMENT_COUNT(1); 0808 return DMath::decodeIeee754(args.at(0), 8, 23); 0809 } 0810 0811 Quantity function_ieee754_single_encode(Function* f, const Function::ArgumentList& args) 0812 { 0813 /* TODO : complex mode switch for this function */ 0814 ENSURE_ARGUMENT_COUNT(1); 0815 return DMath::encodeIeee754(args.at(0), 8, 23); 0816 } 0817 0818 Quantity function_ieee754_double_decode(Function* f, const Function::ArgumentList& args) 0819 { 0820 /* TODO : complex mode switch for this function */ 0821 ENSURE_ARGUMENT_COUNT(1); 0822 return DMath::decodeIeee754(args.at(0), 11, 52); 0823 } 0824 0825 Quantity function_ieee754_double_encode(Function* f, const Function::ArgumentList& args) 0826 { 0827 /* TODO : complex mode switch for this function */ 0828 ENSURE_ARGUMENT_COUNT(1); 0829 return DMath::encodeIeee754(args.at(0), 11, 52); 0830 } 0831 0832 Quantity function_ieee754_quad_decode(Function* f, const Function::ArgumentList& args) 0833 { 0834 /* TODO : complex mode switch for this function */ 0835 ENSURE_ARGUMENT_COUNT(1); 0836 return DMath::decodeIeee754(args.at(0), 15, 112); 0837 } 0838 0839 Quantity function_ieee754_quad_encode(Function* f, const Function::ArgumentList& args) 0840 { 0841 /* TODO : complex mode switch for this function */ 0842 ENSURE_ARGUMENT_COUNT(1); 0843 return DMath::encodeIeee754(args.at(0), 15, 112); 0844 } 0845 0846 void FunctionRepo::createFunctions() 0847 { 0848 // Analysis. 0849 FUNCTION_INSERT(abs); 0850 FUNCTION_INSERT(absdev); 0851 FUNCTION_INSERT(average); 0852 FUNCTION_INSERT(bin); 0853 FUNCTION_INSERT(cbrt); 0854 FUNCTION_INSERT(ceil); 0855 FUNCTION_INSERT(dec); 0856 FUNCTION_INSERT(floor); 0857 FUNCTION_INSERT(frac); 0858 FUNCTION_INSERT(gamma); 0859 FUNCTION_INSERT(geomean); 0860 FUNCTION_INSERT(hex); 0861 FUNCTION_INSERT(int); 0862 FUNCTION_INSERT(lngamma); 0863 FUNCTION_INSERT(max); 0864 FUNCTION_INSERT(min); 0865 FUNCTION_INSERT(oct); 0866 FUNCTION_INSERT(product); 0867 FUNCTION_INSERT(round); 0868 FUNCTION_INSERT(sgn); 0869 FUNCTION_INSERT(sqrt); 0870 FUNCTION_INSERT(stddev); 0871 FUNCTION_INSERT(sum); 0872 FUNCTION_INSERT(trunc); 0873 FUNCTION_INSERT(variance); 0874 0875 // Complex. 0876 FUNCTION_INSERT(real); 0877 FUNCTION_INSERT(imag); 0878 FUNCTION_INSERT(conj); 0879 FUNCTION_INSERT(phase); 0880 FUNCTION_INSERT(polar); 0881 FUNCTION_INSERT(cart); 0882 0883 // Discrete. 0884 FUNCTION_INSERT(gcd); 0885 FUNCTION_INSERT(ncr); 0886 FUNCTION_INSERT(npr); 0887 0888 // Probability. 0889 FUNCTION_INSERT(binomcdf); 0890 FUNCTION_INSERT(binommean); 0891 FUNCTION_INSERT(binompmf); 0892 FUNCTION_INSERT(binomvar); 0893 FUNCTION_INSERT(erf); 0894 FUNCTION_INSERT(erfc); 0895 FUNCTION_INSERT(hypercdf); 0896 FUNCTION_INSERT(hypermean); 0897 FUNCTION_INSERT(hyperpmf); 0898 FUNCTION_INSERT(hypervar); 0899 FUNCTION_INSERT(median); 0900 FUNCTION_INSERT(poicdf); 0901 FUNCTION_INSERT(poimean); 0902 FUNCTION_INSERT(poipmf); 0903 FUNCTION_INSERT(poivar); 0904 0905 // Trigonometry. 0906 FUNCTION_INSERT(arccos); 0907 FUNCTION_INSERT(arcosh); 0908 FUNCTION_INSERT(arsinh); 0909 FUNCTION_INSERT(artanh); 0910 FUNCTION_INSERT(arcsin); 0911 FUNCTION_INSERT(arctan); 0912 FUNCTION_INSERT(arctan2); 0913 FUNCTION_INSERT(cos); 0914 FUNCTION_INSERT(cosh); 0915 FUNCTION_INSERT(cot); 0916 FUNCTION_INSERT(csc); 0917 FUNCTION_INSERT(degrees); 0918 FUNCTION_INSERT(exp); 0919 FUNCTION_INSERT(gradians); 0920 FUNCTION_INSERT(lb); 0921 FUNCTION_INSERT(lg); 0922 FUNCTION_INSERT(ln); 0923 FUNCTION_INSERT(log); 0924 FUNCTION_INSERT(radians); 0925 FUNCTION_INSERT(sec); 0926 FUNCTION_INSERT(sin); 0927 FUNCTION_INSERT(sinh); 0928 FUNCTION_INSERT(tan); 0929 FUNCTION_INSERT(tanh); 0930 0931 // Logic. 0932 FUNCTION_INSERT(mask); 0933 FUNCTION_INSERT(unmask); 0934 FUNCTION_INSERT(not); 0935 FUNCTION_INSERT(and); 0936 FUNCTION_INSERT(or); 0937 FUNCTION_INSERT(xor); 0938 FUNCTION_INSERT(shl); 0939 FUNCTION_INSERT(shr); 0940 FUNCTION_INSERT(idiv); 0941 FUNCTION_INSERT(mod); 0942 0943 // IEEE-754. 0944 FUNCTION_INSERT(ieee754_decode); 0945 FUNCTION_INSERT(ieee754_encode); 0946 FUNCTION_INSERT(ieee754_half_decode); 0947 FUNCTION_INSERT(ieee754_half_encode); 0948 FUNCTION_INSERT(ieee754_single_decode); 0949 FUNCTION_INSERT(ieee754_single_encode); 0950 FUNCTION_INSERT(ieee754_double_decode); 0951 FUNCTION_INSERT(ieee754_double_encode); 0952 FUNCTION_INSERT(ieee754_quad_decode); 0953 FUNCTION_INSERT(ieee754_quad_encode); 0954 } 0955 0956 FunctionRepo* FunctionRepo::instance() 0957 { 0958 if (!s_FunctionRepoInstance) { 0959 s_FunctionRepoInstance = new FunctionRepo; 0960 qAddPostRoutine(s_deleteFunctions); 0961 } 0962 return s_FunctionRepoInstance; 0963 } 0964 0965 FunctionRepo::FunctionRepo() 0966 { 0967 createFunctions(); 0968 setNonTranslatableFunctionUsages(); 0969 retranslateText(); 0970 } 0971 0972 void FunctionRepo::insert(Function* function) 0973 { 0974 if (!function) 0975 return; 0976 m_functions.insert(function->identifier().toUpper(), function); 0977 } 0978 0979 Function* FunctionRepo::find(const QString& identifier) const 0980 { 0981 if (identifier.isNull()) 0982 return 0; 0983 return m_functions.value(identifier.toUpper(), 0); 0984 } 0985 0986 QStringList FunctionRepo::getIdentifiers() const 0987 { 0988 QStringList result = m_functions.keys(); 0989 std::transform(result.begin(), result.end(), result.begin(), [](const QString& s) { return s.toLower(); }); 0990 return result; 0991 } 0992 0993 void FunctionRepo::setNonTranslatableFunctionUsages() 0994 { 0995 FUNCTION_USAGE(abs, "x"); 0996 FUNCTION_USAGE(absdev, "x<sub>1</sub>; x<sub>2</sub>; ..."); 0997 FUNCTION_USAGE(arccos, "x"); 0998 FUNCTION_USAGE(and, "x<sub>1</sub>; x<sub>2</sub>; ..."); 0999 FUNCTION_USAGE(arcosh, "x"); 1000 FUNCTION_USAGE(arsinh, "x"); 1001 FUNCTION_USAGE(artanh, "x"); 1002 FUNCTION_USAGE(arcsin, "x"); 1003 FUNCTION_USAGE(arctan, "x"); 1004 FUNCTION_USAGE(arctan2, "x; y"); 1005 FUNCTION_USAGE(average, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1006 FUNCTION_USAGE(bin, "n"); 1007 FUNCTION_USAGE(cart, "x"); 1008 FUNCTION_USAGE(cbrt, "x"); 1009 FUNCTION_USAGE(ceil, "x"); 1010 FUNCTION_USAGE(conj, "x"); 1011 FUNCTION_USAGE(cos, "x"); 1012 FUNCTION_USAGE(cosh, "x"); 1013 FUNCTION_USAGE(cot, "x"); 1014 FUNCTION_USAGE(csc, "x"); 1015 FUNCTION_USAGE(dec, "x"); 1016 FUNCTION_USAGE(degrees, "x"); 1017 FUNCTION_USAGE(erf, "x"); 1018 FUNCTION_USAGE(erfc, "x"); 1019 FUNCTION_USAGE(exp, "x"); 1020 FUNCTION_USAGE(floor, "x"); 1021 FUNCTION_USAGE(frac, "x"); 1022 FUNCTION_USAGE(gamma, "x"); 1023 FUNCTION_USAGE(gcd, "n<sub>1</sub>; n<sub>2</sub>; ..."); 1024 FUNCTION_USAGE(geomean, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1025 FUNCTION_USAGE(gradians, "x"); 1026 FUNCTION_USAGE(hex, "n"); 1027 FUNCTION_USAGE(ieee754_half_decode, "x"); 1028 FUNCTION_USAGE(ieee754_half_encode, "x"); 1029 FUNCTION_USAGE(ieee754_single_decode, "x"); 1030 FUNCTION_USAGE(ieee754_single_encode, "x"); 1031 FUNCTION_USAGE(ieee754_double_decode, "x"); 1032 FUNCTION_USAGE(ieee754_double_encode, "x"); 1033 FUNCTION_USAGE(ieee754_quad_decode, "x"); 1034 FUNCTION_USAGE(ieee754_quad_encode, "x"); 1035 FUNCTION_USAGE(int, "x"); 1036 FUNCTION_USAGE(imag, "x"); 1037 FUNCTION_USAGE(lb, "x"); 1038 FUNCTION_USAGE(lg, "x"); 1039 FUNCTION_USAGE(ln, "x"); 1040 FUNCTION_USAGE(lngamma, "x"); 1041 FUNCTION_USAGE(max, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1042 FUNCTION_USAGE(median, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1043 FUNCTION_USAGE(min, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1044 FUNCTION_USAGE(ncr, "x<sub>1</sub>; x<sub>2</sub>"); 1045 FUNCTION_USAGE(not, "n"); 1046 FUNCTION_USAGE(npr, "x<sub>1</sub>; x<sub>2</sub>"); 1047 FUNCTION_USAGE(oct, "n"); 1048 FUNCTION_USAGE(or, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1049 FUNCTION_USAGE(polar, "x"); 1050 FUNCTION_USAGE(product, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1051 FUNCTION_USAGE(phase, "x"); 1052 FUNCTION_USAGE(radians, "x"); 1053 FUNCTION_USAGE(real, "x"); 1054 FUNCTION_USAGE(sec, "x)"); 1055 FUNCTION_USAGE(sgn, "x"); 1056 FUNCTION_USAGE(sin, "x"); 1057 FUNCTION_USAGE(sinh, "x"); 1058 FUNCTION_USAGE(sqrt, "x"); 1059 FUNCTION_USAGE(stddev, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1060 FUNCTION_USAGE(sum, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1061 FUNCTION_USAGE(tan, "x"); 1062 FUNCTION_USAGE(tanh, "x"); 1063 FUNCTION_USAGE(trunc, "x"); 1064 FUNCTION_USAGE(variance, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1065 FUNCTION_USAGE(xor, "x<sub>1</sub>; x<sub>2</sub>; ..."); 1066 } 1067 1068 void FunctionRepo::setTranslatableFunctionUsages() 1069 { 1070 FUNCTION_USAGE_i18n(binomcdf, i18n("max; trials; probability")); 1071 FUNCTION_USAGE_i18n(binommean, i18n("trials; probability")); 1072 FUNCTION_USAGE_i18n(binompmf, i18n("hits; trials; probability")); 1073 FUNCTION_USAGE_i18n(binomvar, i18n("trials; probability")); 1074 FUNCTION_USAGE_i18n(hypercdf, i18n("max; total; hits; trials")); 1075 FUNCTION_USAGE_i18n(hypermean, i18n("total; hits; trials")); 1076 FUNCTION_USAGE_i18n(hyperpmf, i18n("count; total; hits; trials")); 1077 FUNCTION_USAGE_i18n(hypervar, i18n("total; hits; trials")); 1078 FUNCTION_USAGE_i18n(idiv, i18n("dividend; divisor")); 1079 FUNCTION_USAGE_i18n(ieee754_decode, i18n("x; exponent_bits; significand_bits [; exponent_bias]")); 1080 FUNCTION_USAGE_i18n(ieee754_encode, i18n("x; exponent_bits; significand_bits [; exponent_bias]")); 1081 FUNCTION_USAGE_i18n(log, i18nc("Calculator logarithmic parameter", "base; x")); 1082 FUNCTION_USAGE_i18n(mask, i18nc("Calculator bitmask parameter", "n; bits")); 1083 FUNCTION_USAGE_i18n(mod, i18n("value; modulo")); 1084 FUNCTION_USAGE_i18n(poicdf, i18n("events; average_events")); 1085 FUNCTION_USAGE_i18n(poimean, i18n("average_events")); 1086 FUNCTION_USAGE_i18n(poipmf, i18n("events; average_events")); 1087 FUNCTION_USAGE_i18n(poivar, i18n("average_events")); 1088 FUNCTION_USAGE_i18n(round, i18nc("Calculator rounding parameter", "x [; precision]")); 1089 FUNCTION_USAGE_i18n(shl, i18nc("n; bits", "Calculator shl function parameter")); 1090 FUNCTION_USAGE_i18n(shr, i18nc("n; bits", "Calculator shr function parameter")); 1091 FUNCTION_USAGE_i18n(unmask, i18nc("Calculator unmask function parameter", "n; bits")); 1092 } 1093 1094 void FunctionRepo::setFunctionNames() 1095 { 1096 FUNCTION_NAME(abs, i18n("Absolute Value")); 1097 FUNCTION_NAME(absdev, i18n("Absolute Deviation")); 1098 FUNCTION_NAME(arccos, i18n("Arc Cosine")); 1099 FUNCTION_NAME(and, i18n("Logical AND")); 1100 FUNCTION_NAME(arcosh, i18n("Area Hyperbolic Cosine")); 1101 FUNCTION_NAME(arsinh, i18n("Area Hyperbolic Sine")); 1102 FUNCTION_NAME(artanh, i18n("Area Hyperbolic Tangent")); 1103 FUNCTION_NAME(arcsin, i18n("Arc Sine")); 1104 FUNCTION_NAME(arctan, i18n("Arc Tangent")); 1105 FUNCTION_NAME(arctan2, i18n("Arc Tangent with two Arguments")); 1106 FUNCTION_NAME(average, i18n("Average (Arithmetic Mean)")); 1107 FUNCTION_NAME(bin, i18n("Convert to Binary Representation")); 1108 FUNCTION_NAME(binomcdf, i18n("Binomial Cumulative Distribution Function")); 1109 FUNCTION_NAME(binommean, i18n("Binomial Distribution Mean")); 1110 FUNCTION_NAME(binompmf, i18n("Binomial Probability Mass Function")); 1111 FUNCTION_NAME(binomvar, i18n("Binomial Distribution Variance")); 1112 FUNCTION_NAME(cart, i18n("Convert to Cartesian Notation")); 1113 FUNCTION_NAME(cbrt, i18n("Cube Root")); 1114 FUNCTION_NAME(ceil, i18n("Ceiling")); 1115 FUNCTION_NAME(conj, i18n("Complex Conjugate")); 1116 FUNCTION_NAME(cos, i18n("Cosine")); 1117 FUNCTION_NAME(cosh, i18n("Hyperbolic Cosine")); 1118 FUNCTION_NAME(cot, i18n("Cotangent")); 1119 FUNCTION_NAME(csc, i18n("Cosecant")); 1120 FUNCTION_NAME(dec, i18n("Convert to Decimal Representation")); 1121 FUNCTION_NAME(degrees, i18n("Degrees of Arc")); 1122 FUNCTION_NAME(erf, i18n("Error Function")); 1123 FUNCTION_NAME(erfc, i18n("Complementary Error Function")); 1124 FUNCTION_NAME(exp, i18n("Exponential")); 1125 FUNCTION_NAME(floor, i18n("Floor")); 1126 FUNCTION_NAME(frac, i18n("Fractional Part")); 1127 FUNCTION_NAME(gamma, i18n("Extension of Factorials [= (x-1)!]")); 1128 FUNCTION_NAME(gcd, i18n("Greatest Common Divisor")); 1129 FUNCTION_NAME(geomean, i18n("Geometric Mean")); 1130 FUNCTION_NAME(gradians, i18n("Gradians of arc")); 1131 FUNCTION_NAME(hex, i18n("Convert to Hexadecimal Representation")); 1132 FUNCTION_NAME(hypercdf, i18n("Hypergeometric Cumulative Distribution Function")); 1133 FUNCTION_NAME(hypermean, i18n("Hypergeometric Distribution Mean")); 1134 FUNCTION_NAME(hyperpmf, i18n("Hypergeometric Probability Mass Function")); 1135 FUNCTION_NAME(hypervar, i18n("Hypergeometric Distribution Variance")); 1136 FUNCTION_NAME(idiv, i18n("Integer Quotient")); 1137 FUNCTION_NAME(int, i18n("Integer Part")); 1138 FUNCTION_NAME(imag, i18n("Imaginary Part")); 1139 FUNCTION_NAME(ieee754_decode, i18n("Decode IEEE-754 Binary Value")); 1140 FUNCTION_NAME(ieee754_encode, i18n("Encode IEEE-754 Binary Value")); 1141 FUNCTION_NAME(ieee754_half_decode, i18n("Decode 16-bit Half-Precision Value")); 1142 FUNCTION_NAME(ieee754_half_encode, i18n("Encode 16-bit Half-Precision Value")); 1143 FUNCTION_NAME(ieee754_single_decode, i18n("Decode 32-bit Single-Precision Value")); 1144 FUNCTION_NAME(ieee754_single_encode, i18n("Encode 32-bit Single-Precision Value")); 1145 FUNCTION_NAME(ieee754_double_decode, i18n("Decode 64-bit Double-Precision Value")); 1146 FUNCTION_NAME(ieee754_double_encode, i18n("Encode 64-bit Double-Precision Value")); 1147 FUNCTION_NAME(ieee754_quad_decode, i18n("Decode 128-bit Quad-Precision Value")); 1148 FUNCTION_NAME(ieee754_quad_encode, i18n("Encode 128-bit Quad-Precision Value")); 1149 FUNCTION_NAME(lb, i18n("Binary Logarithm")); 1150 FUNCTION_NAME(lg, i18n("Common Logarithm")); 1151 FUNCTION_NAME(ln, i18n("Natural Logarithm")); 1152 FUNCTION_NAME(lngamma, "ln(abs(Gamma))"); 1153 FUNCTION_NAME(log, i18n("Logarithm to Arbitrary Base")); 1154 FUNCTION_NAME(mask, i18n("Mask to a bit size")); 1155 FUNCTION_NAME(max, i18nc("Calculator function, largest of numbers", "Maximum")); 1156 FUNCTION_NAME(median, i18n("Median Value (50th Percentile)")); 1157 FUNCTION_NAME(min, i18nc("Calculator function, smallest of numbers", "Minimum")); 1158 FUNCTION_NAME(mod, i18n("Modulo")); 1159 FUNCTION_NAME(ncr, i18n("Combination (Binomial Coefficient)")); 1160 FUNCTION_NAME(not, i18n("Logical NOT")); 1161 FUNCTION_NAME(npr, i18n("Permutation (Arrangement)")); 1162 FUNCTION_NAME(oct, i18n("Convert to Octal Representation")); 1163 FUNCTION_NAME(or, i18n("Logical OR")); 1164 FUNCTION_NAME(phase, i18n("Phase of Complex Number")); 1165 FUNCTION_NAME(poicdf, i18n("Poissonian Cumulative Distribution Function")); 1166 FUNCTION_NAME(poimean, i18n("Poissonian Distribution Mean")); 1167 FUNCTION_NAME(poipmf, i18n("Poissonian Probability Mass Function")); 1168 FUNCTION_NAME(poivar, i18n("Poissonian Distribution Variance")); 1169 FUNCTION_NAME(polar, i18n("Convert to Polar Notation")); 1170 FUNCTION_NAME(product, i18n("Product")); 1171 FUNCTION_NAME(radians, i18n("Radians")); 1172 FUNCTION_NAME(real, i18n("Real Part")); 1173 FUNCTION_NAME(round, i18n("Rounding")); 1174 FUNCTION_NAME(sec, i18n("Secant")); 1175 FUNCTION_NAME(shl, i18n("Arithmetic Shift Left")); 1176 FUNCTION_NAME(shr, i18n("Arithmetic Shift Right")); 1177 FUNCTION_NAME(sgn, i18n("Signum")); 1178 FUNCTION_NAME(sin, i18n("Sine")); 1179 FUNCTION_NAME(sinh, i18n("Hyperbolic Sine")); 1180 FUNCTION_NAME(sqrt, i18n("Square Root")); 1181 FUNCTION_NAME(stddev, i18n("Standard Deviation (Square Root of Variance)")); 1182 FUNCTION_NAME(sum, i18n("Sum")); 1183 FUNCTION_NAME(tan, i18n("Tangent")); 1184 FUNCTION_NAME(tanh, i18n("Hyperbolic Tangent")); 1185 FUNCTION_NAME(trunc, i18n("Truncation")); 1186 FUNCTION_NAME(unmask, i18n("Sign-extend a value")); 1187 FUNCTION_NAME(variance, i18nc("Calculator function", "Variance")); 1188 FUNCTION_NAME(xor, i18n("Logical XOR")); 1189 } 1190 1191 void FunctionRepo::retranslateText() 1192 { 1193 setFunctionNames(); 1194 setTranslatableFunctionUsages(); 1195 }