[Gridflow-cvs] [svn] commit: r6431 - in /trunk: doc/flow_classes/#expr-help.pd doc/numop1.pd src/numop1.cxx

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sat Oct 30 13:23:44 EDT 2010


Author: matju
Date: Sat Oct 30 13:23:41 2010
New Revision: 6431

Log:
added [# fact] : numop1 for factorial (including fractional inputs)

Modified:
    trunk/doc/flow_classes/#expr-help.pd
    trunk/doc/numop1.pd
    trunk/src/numop1.cxx

Modified: trunk/doc/flow_classes/#expr-help.pd
==============================================================================
--- trunk/doc/flow_classes/#expr-help.pd (original)
+++ trunk/doc/flow_classes/#expr-help.pd Sat Oct 30 13:23:41 2010
@@ -1,19 +1,19 @@
 #N canvas 467 24 632 642 10;
 #X obj 0 0 doc_h;
-#X obj 3 796 doc_also;
-#X obj 0 816 doc_f;
-#X obj 3 505 doc_c 1..;
-#X obj 14 535 doc_cc any;
-#X obj 97 535 doc_m cany <atom>;
-#X text 232 535 floats and symbols (and commas and semicolons) that
+#X obj 3 904 doc_also;
+#X obj 0 924 doc_f;
+#X obj 3 616 doc_c 1..;
+#X obj 14 646 doc_cc any;
+#X obj 97 646 doc_m cany <atom>;
+#X text 232 646 floats and symbols (and commas and semicolons) that
 will be joined together to form a string which will be interpreted
 in a manner quite similar to what [expr] does.;
-#X obj 14 623 doc_ii 0;
-#X obj 97 623 doc_m i0 bang;
-#X text 232 623 evaluate expression and output result.;
-#X obj 103 796 expr;
-#X obj 139 796 expr~;
-#X obj 181 796 fexpr~;
+#X obj 14 734 doc_ii 0;
+#X obj 97 734 doc_m i0 bang;
+#X text 232 734 evaluate expression and output result.;
+#X obj 103 904 expr;
+#X obj 139 904 expr~;
+#X obj 181 904 fexpr~;
 #X obj 98 43 #expr;
 #X text 135 43 computes the result of the formula(s) you write in it.
 ;
@@ -29,41 +29,54 @@
 like [%].;
 #X text 96 188 it supports $f1 \, $f2 \, $f3 \, etc.;
 #X text 96 203 it does not support $s1 \, $v1 \, etc.;
-#X obj 3 593 doc_i 1..;
-#X obj 97 645 doc_m i0 float;
-#X text 232 645 set value of $f1 and then do like bang.;
-#X obj 14 623 doc_ii other;
-#X obj 97 672 doc_m iother float;
-#X text 232 672 set value of any other $f variable \, such as $f2 \,
+#X obj 3 704 doc_i 1..;
+#X obj 97 756 doc_m i0 float;
+#X text 232 756 set value of $f1 and then do like bang.;
+#X obj 14 734 doc_ii other;
+#X obj 97 778 doc_m iother float;
+#X text 232 778 set value of any other $f variable \, such as $f2 \,
 $f3 \, etc. \; for example \, a float into inlet 6 will set $f7.;
-#X obj 3 708 doc_o 1..;
-#X obj 14 738 doc_oo any;
-#X obj 97 738 doc_m oany float;
-#X text 232 738 the results \, output from right to left \, even though
+#X obj 3 816 doc_o 1..;
+#X obj 14 846 doc_oo any;
+#X obj 97 846 doc_m oany float;
+#X text 232 846 the results \, output from right to left \, even though
 they get computed left-to-right. [#expr] makes a list of the results
 and then outputs it in reverse order.;
 #X text 120 268 [#expr rand($f1)] is the same as [expr random(0 \,
 $f1)];
-#X text 96 289 it supports some functions that have two arguments \,
+#X text 96 369 it supports some functions that have two arguments \,
 which are the following : min max div rem cmp hypot atan2 avg;
-#X text 119 320 [#expr avg($f1 \, $f2)] = [expr ($f1+$f2)/2];
-#X text 119 336 [#expr hypot($f1 \, $f2)] = [expr sqrt($f1*$f1+$f2*$f2)]
+#X text 119 400 [#expr avg($f1 \, $f2)] = [expr ($f1+$f2)/2];
+#X text 119 416 [#expr hypot($f1 \, $f2)] = [expr sqrt($f1*$f1+$f2*$f2)]
 ;
-#X text 119 352 [#expr cmp($f1 \, $f2)] = [expr if($f1<$f2 \, -1 \,
+#X text 119 432 [#expr cmp($f1 \, $f2)] = [expr if($f1<$f2 \, -1 \,
 $f1>$f2)];
-#X text 119 368 [#expr rem($f1 \, $f2)] = [expr $f1 % $f2];
-#X text 122 383 ...;
-#X text 97 401 it supports table lookup but only with a constant table
+#X text 119 448 [#expr rem($f1 \, $f2)] = [expr $f1 % $f2];
+#X text 122 463 ...;
+#X text 97 481 it supports table lookup but only with a constant table
 name (no $s1);
+#X obj 129 555 doc_link numop1 1;
+#X obj 129 577 doc_link numop2 1;
+#X text 206 576 those that have two arguments: blah($f1 \, $f2);
+#X text 392 557 blah($f1);
+#X text 208 557 those that have one argument:;
+#X floatatom 501 223 5 0 0 0 - - -;
+#X floatatom 499 274 5 0 0 0 - - -;
+#X floatatom 486 370 5 0 0 0 - - -;
+#X floatatom 486 324 5 0 0 0 - - -;
+#X obj 487 347 #expr if($f1 \, 42 \, 666);
+#X obj 498 247 #expr pow($f1 \, 3);
+#X text 97 521 all supported functions are (supposed to be) listed
+over there :;
 #X text 96 219 it supports some functions that have a single argument
 \, which are the following : sin cos tan sinh cosh tanh exp log sqrt
-abs rand;
-#X text 95 432 all supported functions are listed over there :;
-#X obj 129 455 doc_link numop1 1;
-#X obj 129 477 doc_link numop2 1;
-#X text 206 476 those that have two arguments: blah($f1 \, $f2);
-#X text 392 458 blah($f1);
-#X text 208 457 those that have one argument:;
+abs rand fact;
+#X text 121 283 [expr fact(0)] == 0 \, which is contrary to all mathbooks
+;
+#X text 123 316 fact($f1) works on fractional numbers in a way consistent
+with math textbooks. it is the integral of pow(t \, $f1)*exp(-t) for
+all t from 0 to +infinity.;
+#X text 121 300 [#expr fact(0)] == 1 \, which is standard;
 #X connect 1 1 10 0;
 #X connect 1 1 11 0;
 #X connect 1 1 12 0;
@@ -72,3 +85,7 @@
 #X connect 25 1 26 0;
 #X connect 28 1 29 0;
 #X connect 32 1 33 0;
+#X connect 47 0 52 0;
+#X connect 50 0 51 0;
+#X connect 51 0 49 0;
+#X connect 52 0 48 0;

Modified: trunk/doc/numop1.pd
==============================================================================
--- trunk/doc/numop1.pd (original)
+++ trunk/doc/numop1.pd Sat Oct 30 13:23:41 2010
@@ -194,6 +194,9 @@
 If you need complex numbers but don't know yet how they work \, learn
 them using a math tutorial and then those VecOps will begin to look
 familiar.;
+#X msg 10 488 op fact;
+#X text 97 481 factorial. this is the integral of pow(t \, $f1)*exp(-t)
+from 0 to +inf. don't confuse with op gamma.;
 #X connect 54 0 63 0;
 #X connect 56 0 63 0;
 #X connect 58 0 63 0;
@@ -223,3 +226,4 @@
 #X connect 113 0 63 0;
 #X connect 117 0 63 0;
 #X connect 118 0 63 0;
+#X connect 127 0 63 0;

Modified: trunk/src/numop1.cxx
==============================================================================
--- trunk/src/numop1.cxx (original)
+++ trunk/src/numop1.cxx Sat Oct 30 13:23:41 2010
@@ -100,15 +100,15 @@
 DEF_OP(finite, finite(a))
 DEF_OP(isnan, isnan(a))
 
+static double fact (double x) {
+	int sign=0;
+	double y = exp(lgamma_r(x+1,&sign));
+	if (1/y) return y*sign; else return 0/0.f;
+}
+DEF_OP(fact, fact(a))
+
 Numop1 op_table_unary[] = {
-	DECL_OP(unary_minus, "unary-"),
-	DECL_OP(logic_not, "!"),
-	DECL_OP(not, "~"),
-	DECL_OP(abs, "abs"),
-	//DECL_OP(asin, "asin"),
-	//DECL_OP(acos, "acos"),
-	//DECL_OP(atan, "atan"), // but atan is already reserved by a c° function.
-
+// moved from numop2 at 9.12
 	DECL_OP(sqrt, "sqrt"),
 	DECL_OP(rand, "rand"),
 	DECL_OP_FLOAT(sin,  "sin"),   DECL_VOP_FLOAT(cx_sin,  "C.sin",  2),
@@ -119,17 +119,26 @@
 	DECL_OP_FLOAT(tanh, "tanh"),  DECL_VOP_FLOAT(cx_tanh, "C.tanh", 2),
 	DECL_OP_FLOAT(exp,  "exp"),   DECL_VOP_FLOAT(cx_exp,  "C.exp",  2),
 	DECL_OP_FLOAT(log,  "log"),   DECL_VOP_FLOAT(cx_log,  "C.log",  2),
+// introduced at 9.12
+	DECL_OP(unary_minus, "unary-"),
+	DECL_OP(logic_not, "!"),
+	DECL_OP(not, "~"),
+	DECL_OP(abs, "abs"),
 	DECL_OP_FLOAT(erf,  "erf"),
 	DECL_OP_FLOAT(erfc, "erfc"),
 	DECL_OP_FLOAT(cbrt, "cbrt"),
 	DECL_OP_FLOAT(expm1, "expm1"),
 	DECL_OP_FLOAT(log1p, "log1p"),
-	
 	DECL_OP_FLOAT(floor, "floor"),
 	DECL_OP_FLOAT(ceil, "ceil"),
+// 9.13
+	DECL_OP(fact, "fact"),
 //	DECL_OP_FLOAT(isinf, "isinf"),
 //	DECL_OP_FLOAT(finite, "finite"),
 //	DECL_OP_FLOAT(isnan, "isnan"),
+	//DECL_OP(asin, "asin"),
+	//DECL_OP(acos, "acos"),
+	//DECL_OP(atan, "atan"), // but atan is already reserved by a c° function.
 };
 const long op_table_unary_n = COUNT(op_table_unary);
 



More information about the Gridflow-cvs mailing list