26#include "valueconverter.h"
48Value func_complex_imag (valVector args,
ValueCalc *calc, FuncExtra *);
49Value func_complex_real (valVector args,
ValueCalc *calc, FuncExtra *);
62Value func_imargument (valVector args,
ValueCalc *calc, FuncExtra *);
63Value func_imconjugate (valVector args,
ValueCalc *calc, FuncExtra *);
69Value func_improduct (valVector args,
ValueCalc *calc, FuncExtra *);
79void RegisterEngineeringFunctions()
81 FunctionRepository* repo = FunctionRepository::self();
84 f =
new Function (
"BASE", func_base);
85 f->setParamCount (1, 3);
87 f =
new Function (
"BESSELI", func_besseli);
90 f =
new Function (
"BESSELJ", func_besselj);
93 f =
new Function (
"BESSELK", func_besselk);
96 f =
new Function (
"BESSELY", func_bessely);
99 f =
new Function (
"BIN2DEC", func_bin2dec);
101 f =
new Function (
"BIN2OCT", func_bin2oct);
103 f =
new Function (
"BIN2HEX", func_bin2hex);
105 f =
new Function (
"COMPLEX", func_complex);
106 f->setParamCount (2);
108 f =
new Function (
"CONVERT", func_convert);
109 f->setParamCount (3);
111 f =
new Function (
"DEC2HEX", func_dec2hex);
113 f =
new Function (
"DEC2BIN", func_dec2bin);
115 f =
new Function (
"DEC2OCT", func_dec2oct);
117 f =
new Function (
"DELTA", func_delta);
118 f->setParamCount (1, 2);
120 f =
new Function (
"ERF", func_erf);
121 f->setParamCount (2);
123 f =
new Function (
"ERFC", func_erfc);
124 f->setParamCount (1, 2);
126 f =
new Function (
"GESTEP", func_gestep);
127 f->setParamCount (1, 2);
129 f =
new Function (
"HEX2BIN", func_hex2bin);
131 f =
new Function (
"HEX2DEC", func_hex2dec);
133 f =
new Function (
"HEX2OCT", func_hex2oct);
135 f =
new Function (
"IMABS", func_imabs);
137 f =
new Function (
"IMAGINARY", func_complex_imag);
139 f =
new Function (
"IMARGUMENT", func_imargument);
141 f =
new Function (
"IMCONJUGATE", func_imconjugate);
143 f =
new Function (
"IMCOS", func_imcos);
145 f =
new Function (
"IMDIV", func_imdiv);
146 f->setParamCount (1, -1);
147 f->setAcceptArray ();
149 f =
new Function (
"IMEXP", func_imexp);
151 f =
new Function (
"IMLN", func_imln);
153 f =
new Function (
"IMPOWER", func_impower);
154 f->setParamCount (2);
156 f =
new Function (
"IMPRODUCT", func_improduct);
157 f->setParamCount (1, -1);
158 f->setAcceptArray ();
160 f =
new Function (
"IMREAL", func_complex_real);
162 f =
new Function (
"IMSIN", func_imsin);
164 f =
new Function (
"IMSQRT", func_imsqrt);
166 f =
new Function (
"IMSUB", func_imsub);
167 f->setParamCount (1, -1);
168 f->setAcceptArray ();
170 f =
new Function (
"IMSUM", func_imsum);
171 f->setParamCount (1, -1);
172 f->setAcceptArray ();
174 f =
new Function (
"OCT2BIN", func_oct2bin);
176 f =
new Function (
"OCT2DEC", func_oct2dec);
178 f =
new Function (
"OCT2HEX", func_oct2hex);
187 if (args.count() > 1)
188 base = calc->conv()->asInteger (args[1]).
asInteger();
189 if (args.count() == 3)
190 prec = calc->conv()->asInteger (args[2]).
asInteger();
192 if ((base < 2) || (base > 36))
194 if (prec < 0) prec = 2;
196 return calc->
base (args[0], base, prec);
212 return calc->besselj (y, x);
220 return calc->besselk (y, x);
228 return calc->besseln (y, x);
234 return calc->
base (args[0], 16);
240 return calc->
base (args[0], 8);
246 return calc->
base (args[0], 2);
288 return calc->
fromBase (args[0], 16);
308static double kspread_convert_prefix( TQMap<TQString,double> map, TQString& unit )
310 if( map.contains( unit ) )
314 static TQMap<char,double> prefixMap;
315 if( prefixMap.isEmpty() )
317 prefixMap[
'E' ] = 1e18;
318 prefixMap[
'P' ] = 1e15;
319 prefixMap[
'T' ] = 1e12;
320 prefixMap[
'G' ] = 1e9;
321 prefixMap[
'M' ] = 1e6;
322 prefixMap[
'k' ] = 1e3;
323 prefixMap[
'h' ] = 1e2;
324 prefixMap[
'e' ] = 1e1;
325 prefixMap[
'd' ] = 1e1;
326 prefixMap[
'c' ] = 1e2;
327 prefixMap[
'm' ] = 1e3;
328 prefixMap[
'u' ] = 1e6;
329 prefixMap[
'n' ] = 1e9;
330 prefixMap[
'p' ] = 1e12;
331 prefixMap[
'f' ] = 1e15;
332 prefixMap[
'a' ] = 1e18;
336 char prefix = unit[0].latin1();
337 if( prefixMap.contains( prefix ) )
340 return prefixMap[ prefix ];
347static bool kspread_convert_mass(
const TQString& fromUnit,
348 const TQString& toUnit,
double value,
double& result )
350 static TQMap<TQString, double> massMap;
353 if( massMap.isEmpty() )
355 massMap[
"g" ] = 1.0;
356 massMap[
"sg" ] = 6.8522050005347800E-05;
357 massMap[
"lbm" ] = 2.2046229146913400E-03;
358 massMap[
"u" ] = 6.0221370000000000E23;
359 massMap[
"ozm" ] = 3.5273971800362700E-02;
360 massMap[
"stone" ] = 1.574730e-04;
361 massMap[
"ton" ] = 1.102311e-06;
362 massMap[
"grain" ] = 1.543236E01;
363 massMap[
"pweight" ] = 7.054792E-01;
364 massMap[
"hweight" ] = 1.968413E-05;
365 massMap[
"shweight" ] = 2.204623E-05;
366 massMap[
"brton" ] = 9.842065E-07;
369 TQString fromU = fromUnit;
370 TQString toU = toUnit;
371 double fromPrefix = kspread_convert_prefix( massMap, fromU );
372 double toPrefix = kspread_convert_prefix( massMap, toU );
373 if( fromPrefix == 0.0 )
return false;
374 if( toPrefix == 0.0 )
return false;
375 if( !massMap.contains( fromU ) )
return false;
376 if( !massMap.contains( toU ) )
return false;
378 result = value * fromPrefix * massMap[toU] / (massMap[fromU] * toPrefix);
384static bool kspread_convert_distance(
const TQString& fromUnit,
385 const TQString& toUnit,
double value,
double& result )
387 static TQMap<TQString, double> distanceMap;
390 if( distanceMap.isEmpty() )
392 distanceMap[
"m" ] = 1.0;
393 distanceMap[
"in" ] = 1.0 / 0.0254;
394 distanceMap[
"ft" ] = 1.0 / (12.0 * 0.0254);
395 distanceMap[
"yd" ] = 1.0 / (3.0 * 12.0 * 0.0254);
396 distanceMap[
"mi" ] = 6.2137119223733397e-4;
397 distanceMap[
"Nmi" ] = 5.3995680345572354e-04;
398 distanceMap[
"ang" ] = 1e10;
399 distanceMap[
"parsec" ] = 3.240779e-17;
400 distanceMap[
"lightyear" ] = 1.057023455773293e-16;
403 TQString fromU = fromUnit;
404 TQString toU = toUnit;
405 double fromPrefix = kspread_convert_prefix( distanceMap, fromU );
406 double toPrefix = kspread_convert_prefix( distanceMap, toU );
407 if( fromPrefix == 0.0 )
return false;
408 if( toPrefix == 0.0 )
return false;
409 if( !distanceMap.contains( fromU ) )
return false;
410 if( !distanceMap.contains( toU ) )
return false;
412 result = value * fromPrefix * distanceMap[toU] / (distanceMap[fromU] * toPrefix);
417static bool kspread_convert_pressure(
const TQString& fromUnit,
418 const TQString& toUnit,
double value,
double& result )
420 static TQMap<TQString, double> pressureMap;
423 if( pressureMap.isEmpty() )
425 pressureMap[
"Pa" ] = 1.0;
426 pressureMap[
"atm" ] = 0.9869233e-5;
427 pressureMap[
"mmHg" ] = 0.00750061708;
428 pressureMap[
"psi" ] = 1 / 6894.754;
429 pressureMap[
"Torr" ] = 1 / 133.32237;
432 TQString fromU = fromUnit;
433 TQString toU = toUnit;
434 double fromPrefix = kspread_convert_prefix( pressureMap, fromU );
435 double toPrefix = kspread_convert_prefix( pressureMap, toU );
436 if( fromPrefix == 0.0 )
return false;
437 if( toPrefix == 0.0 )
return false;
438 if( !pressureMap.contains( fromU ) )
return false;
439 if( !pressureMap.contains( toU ) )
return false;
441 result = value * fromPrefix * pressureMap[toU] / (pressureMap[fromU] * toPrefix);
446static bool kspread_convert_force(
const TQString& fromUnit,
447 const TQString& toUnit,
double value,
double& result )
449 static TQMap<TQString, double> forceMap;
452 if( forceMap.isEmpty() )
454 forceMap[
"N" ] = 1.0;
455 forceMap[
"dyn" ] = 1.0e5;
456 forceMap[
"pond" ] = 1.019716e2;
459 TQString fromU = fromUnit;
460 TQString toU = toUnit;
461 double fromPrefix = kspread_convert_prefix( forceMap, fromU );
462 double toPrefix = kspread_convert_prefix( forceMap, toU );
463 if( fromPrefix == 0.0 )
return false;
464 if( toPrefix == 0.0 )
return false;
465 if( !forceMap.contains( fromU ) )
return false;
466 if( !forceMap.contains( toU ) )
return false;
468 result = value * fromPrefix * forceMap[toU] / (forceMap[fromU] * toPrefix);
473static bool kspread_convert_energy(
const TQString& fromUnit,
474 const TQString& toUnit,
double value,
double& result )
476 static TQMap<TQString, double> energyMap;
479 if( energyMap.isEmpty() )
481 energyMap[
"J" ] = 1.0;
482 energyMap[
"e" ] = 1.0e7;
483 energyMap[
"c" ] = 0.239006249473467;
484 energyMap[
"cal" ] = 0.238846190642017;
485 energyMap[
"eV" ] = 6.241457e+18;
486 energyMap[
"HPh" ] = 3.72506111e-7;
487 energyMap[
"Wh" ] = 0.000277778;
488 energyMap[
"flb" ] = 23.73042222;
489 energyMap[
"BTU" ] = 9.47815067349015e-4;
492 TQString fromU = fromUnit;
493 TQString toU = toUnit;
494 double fromPrefix = kspread_convert_prefix( energyMap, fromU );
495 double toPrefix = kspread_convert_prefix( energyMap, toU );
496 if( fromPrefix == 0.0 )
return false;
497 if( toPrefix == 0.0 )
return false;
498 if( !energyMap.contains( fromU ) )
return false;
499 if( !energyMap.contains( toU ) )
return false;
501 result = value * fromPrefix * energyMap[toU] / (energyMap[fromU] * toPrefix);
506static bool kspread_convert_power(
const TQString& fromUnit,
507 const TQString& toUnit,
double value,
double& result )
509 static TQMap<TQString, double> powerMap;
512 if( powerMap.isEmpty() )
514 powerMap[
"W" ] = 1.0;
515 powerMap[
"HP" ] = 1.341022e-3;
516 powerMap[
"PS" ] = 1.359622e-3;
519 TQString fromU = fromUnit;
520 TQString toU = toUnit;
521 double fromPrefix = kspread_convert_prefix( powerMap, fromU );
522 double toPrefix = kspread_convert_prefix( powerMap, toU );
523 if( fromPrefix == 0.0 )
return false;
524 if( toPrefix == 0.0 )
return false;
525 if( !powerMap.contains( fromU ) )
return false;
526 if( !powerMap.contains( toU ) )
return false;
528 result = value * fromPrefix * powerMap[toU] / (powerMap[fromU] * toPrefix);
533static bool kspread_convert_magnetism(
const TQString& fromUnit,
534 const TQString& toUnit,
double value,
double& result )
536 static TQMap<TQString, double> magnetismMap;
539 if( magnetismMap.isEmpty() )
541 magnetismMap[
"T" ] = 1.0;
542 magnetismMap[
"ga" ] = 1.0e4;
545 TQString fromU = fromUnit;
546 TQString toU = toUnit;
547 double fromPrefix = kspread_convert_prefix( magnetismMap, fromU );
548 double toPrefix = kspread_convert_prefix( magnetismMap, toU );
549 if( fromPrefix == 0.0 )
return false;
550 if( toPrefix == 0.0 )
return false;
551 if( !magnetismMap.contains( fromU ) )
return false;
552 if( !magnetismMap.contains( toU ) )
return false;
554 result = value * fromPrefix * magnetismMap[toU] / (magnetismMap[fromU] * toPrefix);
559static bool kspread_convert_temperature(
const TQString& fromUnit,
560 const TQString& toUnit,
double value,
double& result )
562 static TQMap<TQString, double> tempFactorMap;
563 static TQMap<TQString, double> tempOffsetMap;
566 if( tempFactorMap.isEmpty() || tempOffsetMap.isEmpty() )
568 tempFactorMap[
"C" ] = 1.0; tempOffsetMap[
"C" ] = 0.0;
569 tempFactorMap[
"F" ] = 5.0/9.0; tempOffsetMap[
"F" ] = -32.0;
570 tempFactorMap[
"K" ] = 1.0; tempOffsetMap[
"K" ] = -273.15;
573 if( !tempFactorMap.contains( fromUnit ) )
return false;
574 if( !tempOffsetMap.contains( fromUnit ) )
return false;
575 if( !tempFactorMap.contains( toUnit ) )
return false;
576 if( !tempOffsetMap.contains( toUnit ) )
return false;
578 result = ( value + tempOffsetMap[ fromUnit ] )* tempFactorMap[ fromUnit ];
579 result = ( result / tempFactorMap[ toUnit ] ) - tempOffsetMap[ toUnit ];
584static bool kspread_convert_volume(
const TQString& fromUnit,
585 const TQString& toUnit,
double value,
double& result )
587 static TQMap<TQString, double> volumeMap;
590 if( volumeMap.isEmpty() )
592 volumeMap[
"l" ] = 1.0;
593 volumeMap[
"tsp" ] = 202.84;
594 volumeMap[
"tbs" ] = 67.6133333333333;
595 volumeMap[
"oz" ] = 33.8066666666667;
596 volumeMap[
"cup" ] = 4.22583333333333;
597 volumeMap[
"pt" ] = 2.11291666666667;
598 volumeMap[
"qt" ] = 1.05645833333333;
599 volumeMap[
"gal" ] = 0.26411458333333;
600 volumeMap[
"m3" ] = 1.0e-3;
601 volumeMap[
"mi3" ] = 2.3991275857892772e-13;
602 volumeMap[
"Nmi3" ] = 1.5742621468581148e-13;
603 volumeMap[
"in3" ] = 6.1023744094732284e1;
604 volumeMap[
"ft3" ] = 3.5314666721488590e-2;
605 volumeMap[
"yd3" ] = 1.3079506193143922;
606 volumeMap[
"barrel" ] = 6.289811E-03;
609 TQString fromU = fromUnit;
610 TQString toU = toUnit;
611 double fromPrefix = kspread_convert_prefix( volumeMap, fromU );
612 double toPrefix = kspread_convert_prefix( volumeMap, toU );
613 if( fromPrefix == 0.0 )
return false;
614 if( toPrefix == 0.0 )
return false;
615 if( !volumeMap.contains( fromU ) )
return false;
616 if( !volumeMap.contains( toU ) )
return false;
618 result = value * fromPrefix * volumeMap[toU] / (volumeMap[fromU] * toPrefix);
623static bool kspread_convert_area(
const TQString& fromUnit,
624 const TQString& toUnit,
double value,
double& result )
626 static TQMap<TQString, double> areaMap;
629 if( areaMap.isEmpty() )
631 areaMap[
"m2" ] = 1.0;
632 areaMap[
"mi2" ] = 3.8610215854244585e-7;
633 areaMap[
"Nmi2" ] = 2.9155334959812286e-7;
634 areaMap[
"in2" ] = 1.5500031000062000e3;
635 areaMap[
"ft2" ] = 1.0763910416709722e1;
636 areaMap[
"yd2" ] = 1.0936132983377078;
637 areaMap[
"acre" ] = 4.046856e3;
638 areaMap[
"ha" ] = 1.0e4;
641 TQString fromU = fromUnit;
642 TQString toU = toUnit;
643 double fromPrefix = kspread_convert_prefix( areaMap, fromU );
644 double toPrefix = kspread_convert_prefix( areaMap, toU );
645 if( fromPrefix == 0.0 )
return false;
646 if( toPrefix == 0.0 )
return false;
647 if( !areaMap.contains( fromU ) )
return false;
648 if( !areaMap.contains( toU ) )
return false;
650 result = value * fromPrefix * areaMap[toU] / (areaMap[fromU] * toPrefix);
655static bool kspread_convert_speed(
const TQString& fromUnit,
656 const TQString& toUnit,
double value,
double& result )
658 static TQMap<TQString, double> speedMap;
661 if( speedMap.isEmpty() )
663 speedMap[
"m/s" ] = 1.0;
664 speedMap[
"m/h" ] = 3.6e3;
665 speedMap[
"mph" ] = 2.2369362920544023;
666 speedMap[
"kn" ] = 1.9438444924406048;
669 TQString fromU = fromUnit;
670 TQString toU = toUnit;
671 double fromPrefix = kspread_convert_prefix( speedMap, fromU );
672 double toPrefix = kspread_convert_prefix( speedMap, toU );
673 if( fromPrefix == 0.0 )
return false;
674 if( toPrefix == 0.0 )
return false;
675 if( !speedMap.contains( fromU ) )
return false;
676 if( !speedMap.contains( toU ) )
return false;
678 result = value * fromPrefix * speedMap[toU] / (speedMap[fromU] * toPrefix);
689 double value = calc->conv()->asFloat (args[0]).
asFloat ();
690 TQString fromUnit = calc->conv()->asString (args[1]).
asString();
691 TQString toUnit = calc->conv()->asString (args[2]).
asString();
693 double result = value;
695 if( !kspread_convert_mass( fromUnit, toUnit, value, result ) )
696 if( !kspread_convert_distance( fromUnit, toUnit, value, result ) )
697 if( !kspread_convert_pressure( fromUnit, toUnit, value, result ) )
698 if( !kspread_convert_force( fromUnit, toUnit, value, result ) )
699 if( !kspread_convert_energy( fromUnit, toUnit, value, result ) )
700 if( !kspread_convert_power( fromUnit, toUnit, value, result ) )
701 if( !kspread_convert_magnetism( fromUnit, toUnit, value, result ) )
702 if( !kspread_convert_temperature( fromUnit, toUnit, value, result ) )
703 if( !kspread_convert_volume( fromUnit, toUnit, value, result ) )
704 if( !kspread_convert_area( fromUnit, toUnit, value, result ) )
705 if( !kspread_convert_speed( fromUnit, toUnit, value, result ) )
708 return Value (result);
716static TQString func_create_complex(
double real,
double imag )
721 return TDEGlobal::locale()->formatNumber( real);
724 tmp=TDEGlobal::locale()->formatNumber(real);
726 return TDEGlobal::locale()->formatNumber(imag)+
"i";
728 tmp=tmp+
"+"+TDEGlobal::locale()->formatNumber(imag)+
"i";
730 tmp=tmp+TDEGlobal::locale()->formatNumber(imag)+
"i";
738 if (calc->
isZero (args[1]))
740 double re = calc->conv()->asFloat (args[0]).
asFloat ();
741 double im = calc->conv()->asFloat (args[1]).
asFloat ();
742 TQString tmp=func_create_complex (re, im);
744 double result = TDEGlobal::locale()->readNumber(tmp, &ok);
746 return Value (result);
751static double imag_complexe(TQString str,
bool &ok)
759else if( tmp.length()==1)
765else if( tmp.length()==2 )
769 if((pos1=tmp.find(
'+'))!=-1&& pos1==0)
774 else if( (pos1=tmp.find(
'-'))!=-1 && pos1==0 )
779 else if(tmp[0].isDigit())
782 return TDEGlobal::locale()->readNumber(tmp.left(1));
793 if((pos1=tmp.find(
'i'))!=-1)
798 if((pos2=tmp.findRev(
'+'))!=-1 && pos2!=0)
807 tmpStr=tmp.mid(pos2,(pos1-pos2));
808 val=TDEGlobal::locale()->readNumber(tmpStr, &ok);
814 else if( (pos2=tmp.findRev(
'-'))!=-1&& pos2!=0)
823 tmpStr=tmp.mid(pos2,(pos1-pos2));
824 val=TDEGlobal::locale()->readNumber(tmpStr, &ok);
832 tmpStr=tmp.left(pos1);
833 val=TDEGlobal::locale()->readNumber(tmpStr, &ok);
845Value func_complex_imag (valVector args,
ValueCalc *calc, FuncExtra *)
847 TQString tmp = calc->conv()->asString (args[0]).
asString ();
849 double result=imag_complexe(tmp, good);
851 return Value (result);
856static double real_complexe(TQString str,
bool &ok)
862if((pos1=tmp.find(
'i'))==-1)
864 val=TDEGlobal::locale()->readNumber(tmp, &ok);
871 if((pos2=tmp.findRev(
'-'))!=-1 && pos2!=0)
873 tmpStr=tmp.left(pos2);
874 val=TDEGlobal::locale()->readNumber(tmpStr, &ok);
879 else if((pos2=tmp.findRev(
'+'))!=-1)
881 tmpStr=tmp.left(pos2);
882 val=TDEGlobal::locale()->readNumber(tmpStr, &ok);
899Value func_complex_real (valVector args,
ValueCalc *calc, FuncExtra *)
901 TQString tmp = calc->conv()->asString (args[0]).
asString ();
903 double result=real_complexe(tmp, good);
905 return Value (result);
910 double &imag,
double &real,
double &imag1,
double &real1)
913 imag=imag_complexe(res.
asString(), ok);
914 real=real_complexe(res.
asString(), ok);
917 imag1 = imag_complexe (val.
asString(), ok);
918 real1 = real_complexe (val.
asString(), ok);
921 real1=c->conv()->asFloat (val).
asFloat();
927 double imag,real,imag1,real1;
928 ImHelper (c, res, val, imag, real, imag1, real1);
929 res=func_create_complex(real+real1,imag+imag1);
934 double imag,real,imag1,real1;
935 ImHelper (c, res, val, imag, real, imag1, real1);
936 res=func_create_complex(real-real1,imag-imag1);
941 double imag,real,imag1,real1;
942 ImHelper (c, res, val, imag, real, imag1, real1);
943 res=func_create_complex(real*real1+(imag*imag1)*-1,real*imag1+real1*imag);
948 double imag,real,imag1,real1;
949 ImHelper (c, res, val, imag, real, imag1, real1);
950 res=func_create_complex((real*real1+imag*imag1)/(real1*real1+imag1*imag1),
951 (real1*imag-real*imag1)/(real1*real1+imag1*imag1));
958 calc->
arrayWalk (args, result, awImSum, 0);
961 TQString res = calc->conv()->asString (result).
asString();
962 double val=TDEGlobal::locale()->readNumber(res, &ok);
965 return Value (result);
972 calc->
arrayWalk (args, result, awImSub, 0);
975 TQString res = calc->conv()->asString (result).
asString();
976 double val=TDEGlobal::locale()->readNumber(res, &ok);
979 return Value (result);
983Value func_improduct (valVector args,
ValueCalc *calc, FuncExtra *)
986 calc->
arrayWalk (args, result, awImMul, 0);
989 TQString res = calc->conv()->asString (result).
asString();
990 double val=TDEGlobal::locale()->readNumber(res, &ok);
993 return Value (result);
1000 calc->
arrayWalk (args, result, awImDiv, 0);
1003 TQString res = calc->conv()->asString (result).
asString();
1004 double val=TDEGlobal::locale()->readNumber(res, &ok);
1007 return Value (result);
1011Value func_imconjugate (valVector args,
ValueCalc *calc, FuncExtra *)
1013 TQString tmp = calc->conv()->asString (args[0]).
asString();
1015 double real=real_complexe(tmp,ok);
1018 double imag=imag_complexe(tmp,ok);
1022 tmp=func_create_complex(real,-imag);
1024 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1026 return Value (result);
1032Value func_imargument (valVector args,
ValueCalc *calc, FuncExtra *)
1034 TQString tmp = calc->conv()->asString (args[0]).
asString();
1036 double real=real_complexe(tmp,ok);
1039 double imag=imag_complexe(tmp,ok);
1044 double arg=atan2(imag,real);
1052 TQString tmp = calc->conv()->asString (args[0]).
asString();
1054 double real=real_complexe(tmp,ok);
1057 double imag=imag_complexe(tmp,ok);
1060 double arg=sqrt(pow(imag,2)+pow(real,2));
1068 TQString tmp = calc->conv()->asString (args[0]).
asString();
1070 double real=real_complexe(tmp,ok);
1073 double imag=imag_complexe(tmp,ok);
1076 double imag_res=sin(real)*sinh(imag);
1077 double real_res=cos(real)*cosh(imag);
1080 tmp=func_create_complex(real_res,-imag_res);
1082 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1084 return Value (result);
1092 TQString tmp = calc->conv()->asString (args[0]).
asString();
1094 double real=real_complexe(tmp,ok);
1097 double imag=imag_complexe(tmp,ok);
1100 double imag_res=cos(real)*sinh(imag);
1101 double real_res=sin(real)*cosh(imag);
1104 tmp=func_create_complex(real_res,imag_res);
1106 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1108 return Value (result);
1116 TQString tmp = calc->conv()->asString (args[0]).
asString();
1118 double real=real_complexe(tmp,ok);
1121 double imag=imag_complexe(tmp,ok);
1125 double arg=sqrt(pow(imag,2)+pow(real,2));
1126 double real_res=log(arg);
1127 double imag_res=atan(imag/real);
1128 tmp=func_create_complex(real_res,imag_res);
1130 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1132 return Value (result);
1140 TQString tmp = calc->conv()->asString (args[0]).
asString();
1142 double real=real_complexe(tmp,ok);
1145 double imag=imag_complexe(tmp,ok);
1148 double imag_res=exp(real)*sin(imag);
1149 double real_res=exp(real)*cos(imag);
1152 tmp=func_create_complex(real_res,imag_res);
1154 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1156 return Value (result);
1164 TQString tmp = calc->conv()->asString (args[0]).
asString();
1166 double real=real_complexe(tmp,ok);
1169 double imag=imag_complexe(tmp,ok);
1172 double arg=sqrt(sqrt(pow(imag,2)+pow(real,2)));
1173 double angle=atan(imag/real);
1175 double real_res=arg*cos((angle/2));
1176 double imag_res=arg*sin((angle/2));
1178 tmp=func_create_complex(real_res,imag_res);
1180 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1182 return Value (result);
1190 TQString tmp = calc->conv()->asString (args[0]).
asString();
1191 double val2 = calc->conv()->asFloat (args[1]).
asFloat();
1193 double real=real_complexe(tmp,ok);
1196 double imag=imag_complexe(tmp,ok);
1200 double arg=::pow(sqrt(pow(imag,2)+pow(real,2)),val2);
1201 double angle=atan(imag/real);
1203 double real_res=arg*cos(angle*val2);
1204 double imag_res=arg*sin(angle*val2);
1206 tmp=func_create_complex(real_res,imag_res);
1208 double result=TDEGlobal::locale()->readNumber(tmp, &ok);
1210 return Value (result);
1218 Value val1 = args[0];
1220 if (args.count() == 2)
1229 if (args.count() == 2)
1230 return calc->sub (calc->
erf (args[1]), calc->
erf (args[0]));
1231 return calc->
erf (args[0]);
1237 if (args.count() == 2)
1238 return calc->sub (calc->erfc (args[1]), calc->erfc (args[0]));
1239 return calc->erfc (args[0]);
1247 if (args.count() == 2)
1254 return Value (result);
The ValueCalc class is used to perform all sorts of calculations.
bool approxEqual(const Value &a, const Value &b)
numerical comparison with a little epsilon tolerance
bool greater(const Value &a, const Value &b)
numerical comparison
Value besseli(Value v, Value x)
bessel functions - may also end up being separated from here
bool isZero(const Value &a)
comparison and related
Value erf(Value x)
error functions (see: man erf)
void arrayWalk(const Value &range, Value &res, arrayWalkFunc func, Value param)
array/range walking
Value fromBase(const Value &val, int base=16)
base conversion base -> 10
Value base(const Value &val, int base=16, int prec=0)
base conversion 10 -> base
Provides a wrapper for cell value.
static const Value & errorDIV0()
Returns constant reference to DIV/0!
double asFloat() const
Returns the floating-point value of this value.
long asInteger() const
Returns the integer value of this value.
TQString asString() const
Returns the string value of this value.
static const Value & errorVALUE()
Returns constant reference to VALUE!
bool isString() const
Returns true if the type of this value is string.
static const Value & errorNA()
Returns constant reference to N/A error.