|
From: <cre...@us...> - 2007-11-14 22:46:57
|
Revision: 1783
http://frontierkernel.svn.sourceforge.net/frontierkernel/?rev=1783&view=rev
Author: creecode
Date: 2007-11-14 14:44:59 -0800 (Wed, 14 Nov 2007)
Log Message:
-----------
adding abs, acos, asin, atan, ceil, cos, cosh, exp, floor, log, log10, sin, sinh, tan, tanh, trunc, power, mod, and rnd functions
Modified Paths:
--------------
Frontier/branches/math_functions/Common/resources/Mac/kernelverbs.r
Frontier/branches/math_functions/Common/resources/Win32/kernelverbs.rc
Frontier/branches/math_functions/Common/source/langmath.c
Modified: Frontier/branches/math_functions/Common/resources/Mac/kernelverbs.r
===================================================================
--- Frontier/branches/math_functions/Common/resources/Mac/kernelverbs.r 2007-11-13 01:21:29 UTC (rev 1782)
+++ Frontier/branches/math_functions/Common/resources/Mac/kernelverbs.r 2007-11-14 22:44:59 UTC (rev 1783)
@@ -1120,18 +1120,39 @@
}
};
-resource 'EFP#' (idmathverbs, "math") { /*2004-12-29 SMD: math verbs*/
-
+
+resource 'EFP#' (idmathverbs, "math") { // 2004-12-29 SMD: math verbs
{
- "math", false, {
-
- "min",
- "max",
- "sqrt"
+ "math", false, {
+
+ "min",
+ "max",
+ "sqrt",
+ "power", // 2007-11-12 dah: added power thru trunc
+ "abs",
+ "acos",
+ "asin",
+ "atan",
+ "ceil",
+ "cos",
+ "cosh",
+ "exp",
+ "floor",
+ "log",
+ "log10",
+ "sin",
+ "sinh",
+ "tan",
+ "tanh",
+ "mod",
+ "rnd",
+ "trunc"
+
+ }
}
- }
-};
+ };
+
resource 'EFP#' (idcryptverbs, "crypt") { // 2006-03-07 creedon: crypt verbs
{
"crypt", false, {
@@ -1146,6 +1167,7 @@
}
};
+
resource 'EFP#' (idsqliteverbs, "sqlite") { // 2006-08-31 gewirtz sqlite verbs
{
"sqlite", false, {
@@ -1172,6 +1194,7 @@
}
};
+
resource 'EFP#' (idmysqlverbs, "mysql") { /* 2007-04-09 gewirtz mysql verbs */
{
"mysql", false, {
Modified: Frontier/branches/math_functions/Common/resources/Win32/kernelverbs.rc
===================================================================
--- Frontier/branches/math_functions/Common/resources/Win32/kernelverbs.rc 2007-11-13 01:21:29 UTC (rev 1782)
+++ Frontier/branches/math_functions/Common/resources/Win32/kernelverbs.rc 2007-11-14 22:44:59 UTC (rev 1783)
@@ -1055,17 +1055,38 @@
#endif //flregexpverbs
-1024 /*mathverbs*/ EFP DISCARDABLE
+
+1024 /* mathverbs */ EFP DISCARDABLE
BEGIN
- 1, //Number of "blocks" in this resource
- "math\0", //Function Processor name
- false, //Window required
- 3, //Count of verbs
+ 1, // Number of "blocks" in this resource
+ "math\0", // Function Processor name
+ false, // Window required
+ 22, // Count of verbs
"min\0",
"max\0",
- "sqrt\0"
+ "sqrt\0",
+ "power\0", // 2007-11-12 dah: added power thru trunc
+ "abs\0",
+ "acos\0",
+ "asin\0",
+ "atan\0",
+ "ceil\0",
+ "cos\0",
+ "cosh\0",
+ "exp\0",
+ "floor\0",
+ "log\0",
+ "log10\0",
+ "sin\0",
+ "sinh\0",
+ "tan\0",
+ "tanh\0",
+ "mod\0",
+ "rnd\0",
+ "trunc\0"
END
+
1025 /* cryptverbs */ EFP DISCARDABLE // 2006-03-07 creedon: crypt verbs
BEGIN
1, // Number of "blocks" in this resource
@@ -1079,6 +1100,7 @@
"hmacSHA1\0"
END
+
1026 /* sqliteverbs */ EFP DISCARDABLE
BEGIN
1, // Number of "blocks" in this resource
@@ -1104,6 +1126,7 @@
"getLastInsertRowId\0" // 2007-08-28 creedon
END
+
1027 /* mysqlverbs */ EFP DISCARDABLE
BEGIN
1, // Number of "blocks" in this resource
@@ -1138,4 +1161,5 @@
"isThreadSafe\0",
"close\0"
END
-
+
+
\ No newline at end of file
Modified: Frontier/branches/math_functions/Common/source/langmath.c
===================================================================
--- Frontier/branches/math_functions/Common/source/langmath.c 2007-11-13 01:21:29 UTC (rev 1782)
+++ Frontier/branches/math_functions/Common/source/langmath.c 2007-11-14 22:44:59 UTC (rev 1783)
@@ -45,32 +45,83 @@
#include "timedate.h"
#include "langmath.h"
+
#define matherrorlist 269
#define notimplementederror 1
-typedef enum tymathtoken { /*verbs that are processed by langmath.c*/
-
+
+typedef enum tymathtoken { // verbs that are processed by langmath.c
+
minfunc,
maxfunc,
sqrtfunc,
+ powerfunc, // 2007-11-12 dah: added powerfunc thru truncfunc
+
+ absfunc,
+
+ acosfunc,
+
+ asinfunc,
+
+ atanfunc,
+
+ ceilfunc,
+
+ cosfunc,
+
+ coshfunc,
+
+ expfunc,
+
+ floorfunc,
+
+ logfunc,
+
+ log10func,
+
+ sinfunc,
+
+ sinhfunc,
+
+ tanfunc,
+
+ tanhfunc,
+
+ modfunc,
+
+ rndfunc,
+
+ truncfunc,
+
cmathverbs
+
} tymathtoken;
+
static boolean mathfunctionvalue (short token, hdltreenode hparam1, tyvaluerecord *vreturned, bigstring bserror) {
+
+ //
+ // 2007-11-06 dah: added absfunc, acosfunc, asinfunc, atanfunc, ceilfunc,
+ // cosfunc, coshfunc, expfunc, floorfunc, logfunc,
+ // log10func, sinfunc, sinhfunc, tanfunc, tanhfunc,
+ // truncfunc cases
+ //
+ // 2007-10-30 dah: added powerfunc, modfunc, rndfunc cases
+ //
hdltreenode hp1 = hparam1;
tyvaluerecord *v = vreturned;
short errornum = 0;
- setbooleanvalue (false, v); /*by default, math functions return false*/
+ setbooleanvalue (false, v); // by default, math functions return false
switch (token) {
- case minfunc: { /* 2004/12/29 smd */
-
+ case minfunc: { // 2004-12-29 smd
+
tyvaluerecord v1, v2;
tyvaluerecord v1copy, v2copy;
tyvaluerecord * vResult = NULL;
@@ -90,90 +141,107 @@
if (!copyvaluerecord (v2, &v2copy)) /* so that we don't coerce the original */
break;
- if (!coercetypes (&v1copy, &v2copy))
- {
+ if (!coercetypes (&v1copy, &v2copy)) {
+
disposevalues (&v1copy, &v2copy);
break;
- }
+
+ }
switch (v1copy.valuetype) {
- case novaluetype: { /* no test needed, nil is nil*/
+ case novaluetype: { // no test needed, nil is nil
+
initvalue (v, novaluetype);
fl = true;
break;
+
}
- case booleanvaluetype: /* if v2 is true, then return v1 (false < true) */
+ case booleanvaluetype: // if v2 is true, then return v1 (false < true)
+
vResult = v2copy.data.flvalue ? &v1 : &v2;
break;
- /* all the rest return the greater of the two values */
+ // all the rest return the greater of the two values
+
case charvaluetype:
+
vResult = ( v1copy.data.chvalue <= v2copy.data.chvalue ) ? &v1 : &v2;
break;
case intvaluetype:
+
vResult = ( v1copy.data.intvalue <= v2copy.data.intvalue ) ? &v1 : &v2;
break;
case longvaluetype:
case ostypevaluetype:
+
vResult = ( v1copy.data.longvalue <= v2copy.data.longvalue ) ? &v1 : &v2;
break;
case directionvaluetype:
+
vResult = ( (short) v1copy.data.dirvalue <= (short) v2copy.data.dirvalue ) ? &v1 : &v2;
break;
case datevaluetype:
+
vResult = timegreaterthan( v2copy.data.datevalue, v1copy.data.datevalue ) ? &v1 : &v2;
break;
case singlevaluetype:
+
vResult = ( v1copy.data.singlevalue <= v2copy.data.singlevalue ) ? &v1 : &v2;
break;
case doublevaluetype:
+
vResult = ( **v1copy.data.doublevalue <= **v2copy.data.doublevalue ) ? &v1 : &v2;
break;
case stringvaluetype:
+
vResult = ( comparehandles( v1copy.data.stringvalue, v2copy.data.stringvalue ) == 1 ) ? &v2 : &v1;
break;
default:
+
langerror (comparisonnotpossibleerror);
fl = false; /*operation is not defined*/
break;
- } /*switch*/
+
+ } // switch
- if ( vResult != NULL )
- {
+ if ( vResult != NULL ) {
+
if ( copyvaluerecord( *vResult, v ) )
fl = true;
disposevalues( &v1copy, &v2copy );
+
+ }
+
+ return ( fl );
+
}
-
- return ( fl );
- }
- case maxfunc: { /* 2004/12/29 smd */
+ case maxfunc: { // 2004-12-29 smd
tyvaluerecord v1, v2;
tyvaluerecord v1copy, v2copy;
@@ -194,90 +262,107 @@
if (!copyvaluerecord (v2, &v2copy)) /* so that we don't coerce the original */
break;
- if (!coercetypes (&v1copy, &v2copy))
- {
+ if (!coercetypes (&v1copy, &v2copy)) {
+
disposevalues (&v1, &v2);
break;
- }
-
+
+ }
+
switch (v1copy.valuetype) {
- case novaluetype: { /* no test needed, nil is nil*/
+ case novaluetype: { // no test needed, nil is nil
+
initvalue (v, novaluetype);
fl = true;
break;
+
}
- case booleanvaluetype: /* if v2 is true, then return v1 (false < true) */
+ case booleanvaluetype: // if v2 is true, then return v1 (false < true)
+
vResult = v1copy.data.flvalue ? &v1 : &v2;
break;
- /* all the rest return the greater of the two values */
+ // all the rest return the greater of the two values
+
case charvaluetype:
+
vResult = ( v1copy.data.chvalue >= v2copy.data.chvalue ) ? &v1 : &v2;
break;
case intvaluetype:
+
vResult = ( v1copy.data.intvalue >= v2copy.data.intvalue ) ? &v1 : &v2;
break;
case longvaluetype:
case ostypevaluetype:
+
vResult = ( v1copy.data.longvalue >= v2copy.data.longvalue ) ? &v1 : &v2;
break;
case directionvaluetype:
+
vResult = ( (short) v1copy.data.dirvalue >= (short) v2copy.data.dirvalue ) ? &v1 : &v2;
break;
case datevaluetype:
+
vResult = timegreaterthan( v1copy.data.datevalue, v2copy.data.datevalue ) ? &v1 : &v2;
break;
case singlevaluetype:
+
vResult = ( v1copy.data.singlevalue >= v2copy.data.singlevalue ) ? &v1 : &v2;
break;
case doublevaluetype:
+
vResult = ( **v1copy.data.doublevalue >= **v2copy.data.doublevalue ) ? &v1 : &v2;
break;
case stringvaluetype:
+
vResult = ( comparehandles( v1copy.data.stringvalue, v2copy.data.stringvalue ) != -1 ) ? &v1 : &v2;
break;
default:
+
langerror (comparisonnotpossibleerror);
fl = false; /*operation is not defined*/
break;
- } /*switch*/
+
+ } // switch
- if ( vResult != NULL )
- {
+ if ( vResult != NULL ) {
+
if ( copyvaluerecord( *vResult, v ) )
fl = true;
-
+
disposevalues( &v1copy, &v2copy );
- }
+
+ }
return ( fl );
- }
+
+ }
- case sqrtfunc: { /* 2004/12/29 smd */
+ case sqrtfunc: { // 2004-12-29 smd
tyvaluerecord v1;
double d;
@@ -290,28 +375,351 @@
d = sqrt (**v1.data.doublevalue);
return (setdoublevalue (d, v));
+
}
+ case powerfunc: {
+
+ tyvaluerecord v1, v2;
+ double d;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 2, &v2))
+ break;
+
+ d = pow (**v1.data.doublevalue, **v2.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case absfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = abs (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case acosfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = acos (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case asinfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = asin (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case atanfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = atan (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case ceilfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = ceil (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case cosfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = cos (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case coshfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = cosh (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case expfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = exp (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case floorfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = floor (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case logfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = log (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case log10func: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = log10 (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case sinfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = sin (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case sinhfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = sinh (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case tanfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = tan (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case tanhfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ d = tanh (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case modfunc: {
+
+ tyvaluerecord v1, v2;
+ double d;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 2, &v2))
+ break;
+
+ d = fmod (**v1.data.doublevalue, **v2.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case rndfunc: {
+
+ tyvaluerecord v1, v2;
+ double d, e;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 2, &v2))
+ break;
+
+ e = pow(10, **v2.data.doublevalue * -1);
+ d = floor((**v1.data.doublevalue * e) + 0.5) / e;
+
+ return (setdoublevalue (d, v));
+
+ }
+
+ case truncfunc: {
+
+ tyvaluerecord v1;
+ double d;
+
+ flnextparamislast = true;
+
+ if (!getdoubleparam (hp1, 1, &v1))
+ break;
+
+ if (**v1.data.doublevalue > 0)
+ d = floor (**v1.data.doublevalue);
+ else
+ d = ceil (**v1.data.doublevalue);
+
+ return (setdoublevalue (d, v));
+
+ }
+
default:
+
errornum = notimplementederror;
goto error;
- } /*switch*/
+
+ } // switch
error:
- if (errornum != 0) /*get error string*/
- getstringlist (matherrorlist, errornum, bserror);
-
- return (false);
- } /*langmathvalue*/
-
+ if (errornum != 0) // get error string
+ getstringlist (matherrorlist, errornum, bserror);
+
+ return (false);
+ } // langmathvalue
+
+
boolean mathinitverbs (void) {
- /*
- 2004-12-29 smd: new math verbs
- */
+ //
+ // 2004-12-29 smd: new math verbs
+ //
return (loadfunctionprocessor (idmathverbs, &mathfunctionvalue));
- } /*mathinitverbs*/
+
+ } // mathinitverbs
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|