diff --git a/pd/doc/5.reference/log-help.pd b/pd/doc/5.reference/log-help.pd index c2cdc6bbbc667f498b12792d79284ff25feca9cd..e2de07e408de4a53c9fbbacc239a455c149062f8 100644 --- a/pd/doc/5.reference/log-help.pd +++ b/pd/doc/5.reference/log-help.pd @@ -1,9 +1,9 @@ -#N canvas 428 60 555 619 10; +#N canvas 626 70 555 619 10; #X obj 0 595 cnv 15 552 21 empty \$0-pddp.cnv.footer empty 20 12 0 14 -228856 -66577 0; #X obj 0 0 cnv 15 552 40 empty \$0-pddp.cnv.header log 3 12 0 18 -204280 -1 0; -#X obj 0 389 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 8 12 0 13 +#X obj 0 299 cnv 3 550 3 empty \$0-pddp.cnv.inlets inlets 8 12 0 13 -228856 -1 0; #N canvas 483 285 494 344 META 0; #X text 12 105 LIBRARY internal; @@ -21,13 +21,12 @@ for Pd version 0.42.; #X text 12 85 OUTLET_0 float; #X text 12 165 RELEASE_DATE 1997; #X restore 500 597 pd META; -#X obj 0 454 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 8 12 0 +#X obj 0 414 cnv 3 550 3 empty \$0-pddp.cnv.outlets outlets 8 12 0 13 -228856 -1 0; -#X obj 0 491 cnv 3 550 3 empty \$0-pddp.cnv.argument arguments 8 12 +#X obj 0 451 cnv 3 550 3 empty \$0-pddp.cnv.argument arguments 8 12 0 13 -228856 -1 0; #X obj 0 518 cnv 3 550 3 empty \$0-pddp.cnv.more_info more_info 8 12 0 13 -228856 -1 0; -#X text 98 495 (none); #N canvas 215 516 428 109 Related_objects 0; #X obj 1 1 cnv 15 425 20 empty \$0-pddp.cnv.subheading empty 3 12 0 14 -204280 -1 0; @@ -45,22 +44,22 @@ for Pd version 0.42.; #X text 7 1 [log] Related Objects; #X obj 181 42 exp; #X restore 101 597 pd Related_objects; -#X obj 78 398 cnv 17 3 45 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 +#X obj 78 308 cnv 17 3 45 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 -162280 0; -#X text 98 397 float; -#X text 98 417 list; -#X text 98 462 float; -#X obj 78 463 cnv 17 3 17 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 +#X text 98 307 float; +#X text 98 327 list; +#X text 98 422 float; +#X obj 78 423 cnv 17 3 17 empty \$0-pddp.cnv.let.0 0 5 9 0 16 -228856 -162280 0; -#X floatatom 239 217 0 0 0 0 - - -; -#X floatatom 239 160 0 0 0 0 - - -; -#X text 94 274 [log] will output the natural logarithm (base E) of +#X floatatom 239 177 0 0 0 0 - - -; +#X floatatom 239 120 0 0 0 0 - - -; +#X text 94 234 [log] will output the natural logarithm (base E) of a number. The value of zero will produce "-1000" which represents "negative infinity".; -#X obj 239 190 log; +#X obj 239 150 log; #X obj 515 9 log; #X text 11 23 natural logarithm of a number; -#X text 168 417 - a list will be truncated \, and the first element +#X text 168 307 - a list will be truncated \, and the first element will be used as input.; #X obj 4 597 pddp/pddplink all_about_help_patches.pd -text Usage Guide ; @@ -70,5 +69,18 @@ will be used as input.; #X obj 98 548 pddp/pddplink otherbinops-help.pd; #X obj 98 568 pddp/pddplink math-help.pd; #X text 217 568 - higher math objects; -#X connect 15 0 17 0; -#X connect 17 0 14 0; +#X floatatom 282 118 5 0 0 1 base_value - -, f 5; +#X obj 33 148 log 2; +#X floatatom 33 173 5 0 0 0 - - -, f 5; +#X floatatom 33 120 5 0 0 0 - - -, f 5; +#X obj 78 358 cnv 17 3 30 empty \$0-pddp.cnv.let.0 1 5 9 0 16 -228856 +-162280 0; +#X text 98 357 float; +#X text 168 357 - set the base; +#X text 78 485 1) float; +#X text 138 485 - set the base; +#X connect 14 0 16 0; +#X connect 16 0 13 0; +#X connect 27 0 16 1; +#X connect 28 0 29 0; +#X connect 30 0 28 0; diff --git a/pd/src/x_arithmetic.c b/pd/src/x_arithmetic.c index 6d4fad6fa6b8fb51ca17a70ad3f8c2216ced8162..57f4402d5de8a21d2ac2fb913809d8ada3ec2d4a 100644 --- a/pd/src/x_arithmetic.c +++ b/pd/src/x_arithmetic.c @@ -636,19 +636,28 @@ static void sqrt_float(t_object *x, t_float f) outlet_float(x->ob_outlet, r); } -static t_class *log_class; /* ----------- log --------------- */ +static t_class *binop1_log_class; /* ----------- log --------------- */ -static void *log_new(void) +static void *binop1_log_new(t_floatarg f) { - t_object *x = (t_object *)pd_new(log_class); - outlet_new(x, &s_float); - return (x); + return (binop1_new(binop1_log_class, f)); } -static void log_float(t_object *x, t_float f) +static void binop1_log_bang(t_binop *x) { - t_float r = (f > 0 ? LOG(f) : -1000); - outlet_float(x->ob_outlet, r); + t_float r; + if (x->x_f1 <= 0) + r = -1000; + else if (x->x_f2 <= 0) + r = LOG(x->x_f1); + else r = LOG(x->x_f1)/LOG(x->x_f2); + outlet_float(x->x_obj.ob_outlet, r); +} + +static void binop1_log_float(t_binop *x, t_float f) +{ + x->x_f1 = f; + binop1_log_bang(x); } static t_class *exp_class; /* ----------- exp --------------- */ @@ -791,6 +800,11 @@ void x_arithmetic_setup(void) class_addbang(binop1_min_class, binop1_min_bang); class_addfloat(binop1_min_class, (t_method)binop1_min_float); + binop1_log_class = class_new(gensym("log"), (t_newmethod)binop1_log_new, + 0, sizeof(t_binop), 0, A_DEFFLOAT, 0); + class_addbang(binop1_log_class, binop1_log_bang); + class_addfloat(binop1_log_class, (t_method)binop1_log_float); + /* ------------------ binop2 ----------------------- */ binop2_ee_class = class_new(gensym("=="), (t_newmethod)binop2_ee_new, 0, @@ -911,10 +925,6 @@ void x_arithmetic_setup(void) sizeof(t_object), 0, 0); class_addfloat(sqrt_class, (t_method)sqrt_float); - log_class = class_new(gensym("log"), log_new, 0, - sizeof(t_object), 0, 0); - class_addfloat(log_class, (t_method)log_float); - exp_class = class_new(gensym("exp"), exp_new, 0, sizeof(t_object), 0, 0); class_addfloat(exp_class, (t_method)exp_float); diff --git a/scripts/regression_tests.pd b/scripts/regression_tests.pd index c3137310fd6ec71ec22d99203460979a26be6603..cf661a67804247163d5fe7b551ff45a83d50a0c0 100644 --- a/scripts/regression_tests.pd +++ b/scripts/regression_tests.pd @@ -1,7 +1,7 @@ -#N canvas 341 181 750 572 12; +#N canvas 243 24 750 572 12; #X obj 465 281 r \$0-result; -#X obj 212 239 bng 15 250 50 0 empty empty Run_all 17 7 0 10 -262144 --1 -1; +#X obj 212 239 bng 15 250 50 0 empty empty Run_all 17 7 0 10 #fcfcfc +#000000 #000000; #X obj 56 25 r init; #X obj 345 191 route dollarzero; #X obj 198 281 rtest msg_dollarzero; @@ -25,13 +25,13 @@ is handy for some binbuf tests.; #X obj 198 659 rtest makefilename_double_percent; #X obj 198 710 rtest makefilename_code_coverage; #N canvas 461 242 450 323 (subpatch) 0; -#X restore 201 2345 pd; +#X restore 201 2415 pd; #X obj 198 761 rtest makefilename_default; #X obj 198 812 rtest makefilename_default_bang; #X obj 198 863 rtest makefilename_float; #X obj 198 914 rtest makefilename_symbol; #X obj 198 965 rtest makefilename_bang; -#X obj 198 1016 rtest drawtext-typecheck; +#X obj 198 1016 rtest drawtext_typecheck; #X obj 465 308 utils/print-result; #X obj 56 231 utils/quit-if-nogui; #X obj 198 1071 rtest list_cat_clear; @@ -60,6 +60,8 @@ is handy for some binbuf tests.; #X obj 198 2086 rtest route_reject_bang; #X obj 198 2141 rtest text_sort; #X obj 198 2196 rtest iemgui_color_symbolargs; +#X obj 198 2251 rtest log_right_inlet; +#X obj 198 2306 rtest log_base; #X connect 0 0 27 0; #X connect 1 0 4 0; #X connect 2 0 42 0; @@ -105,3 +107,5 @@ is handy for some binbuf tests.; #X connect 51 0 52 0; #X connect 52 0 53 0; #X connect 53 0 54 0; +#X connect 54 0 55 0; +#X connect 55 0 56 0; diff --git a/scripts/regression_tests/drawtext-typecheck.pd b/scripts/regression_tests/drawtext_typecheck.pd similarity index 100% rename from scripts/regression_tests/drawtext-typecheck.pd rename to scripts/regression_tests/drawtext_typecheck.pd diff --git a/scripts/regression_tests/log_base.pd b/scripts/regression_tests/log_base.pd new file mode 100644 index 0000000000000000000000000000000000000000..dfa72a7db3b2a0e48a452f737fd93d01a0b2aae5 --- /dev/null +++ b/scripts/regression_tests/log_base.pd @@ -0,0 +1,24 @@ +#N canvas 329 252 685 317 12; +#X obj 57 22 inlet; +#X obj 57 240 outlet; +#X obj 173 111 log; +#X msg 207 83 2; +#X msg 173 83 2; +#X obj 57 51 trigger bang bang bang; +#X obj 173 140 == 1; +#X msg 57 80 2; +#X obj 57 169 log 2; +#X obj 57 198 list append log's argument sets the base; +#X obj 173 169 list append log's right inlet sets the base; +#X connect 0 0 5 0; +#X connect 2 0 6 0; +#X connect 3 0 2 1; +#X connect 4 0 2 0; +#X connect 5 0 7 0; +#X connect 5 1 4 0; +#X connect 5 2 3 0; +#X connect 6 0 10 0; +#X connect 7 0 8 0; +#X connect 8 0 9 0; +#X connect 9 0 1 0; +#X connect 10 0 1 0; diff --git a/scripts/regression_tests/log_right_inlet.pd b/scripts/regression_tests/log_right_inlet.pd new file mode 100644 index 0000000000000000000000000000000000000000..c2b6f680402b5897d9057f85ae8e9571fcab20b7 --- /dev/null +++ b/scripts/regression_tests/log_right_inlet.pd @@ -0,0 +1,14 @@ +#N canvas 328 228 685 317 12; +#X obj 57 22 inlet; +#X obj 57 230 outlet; +#X obj 57 111 ../utils/object-test inlets; +#X msg 57 81 symbol log; +#X obj 57 140 == 2; +#X obj 57 169 list append log has a right inlet for the base; +#X obj 57 51 bang; +#X connect 0 0 6 0; +#X connect 2 0 4 0; +#X connect 3 0 2 0; +#X connect 4 0 5 0; +#X connect 5 0 1 0; +#X connect 6 0 3 0; diff --git a/scripts/utils/creation-test.pd b/scripts/utils/creation-test.pd index 874ae99e2fb27ee85a51abafa3a2aeaf1d25a748..149bd0a6d84e719cfa6c2cf06d149d88a46fdd76 100644 --- a/scripts/utils/creation-test.pd +++ b/scripts/utils/creation-test.pd @@ -1,59 +1,18 @@ -#N canvas 311 60 683 597 12; -#X text 97 22 Simple abstraction to test object creation; -#N canvas 82 171 450 346 \$0-test 0; -#X obj 200 20 receive 1004-in; -#X obj 200 60 canvasinfo; -#X obj 200 100 send 1004-out; -#X obj 0 0 cxc/hex2dec; +#N canvas 247 65 536 318 12; +#X obj 46 36 inlet; +#X obj 46 65 object-test class; +#X obj 46 94 select text; +#X msg 46 123 0; +#X obj 120 123 b; +#X msg 120 152 1; +#X obj 46 202 outlet; +#X text 107 193 simple creation test. if the object we tried to create +has the "text" class \, we know it's a broken object. Otherwise \, +it should have created successfully.; #X connect 0 0 1 0; #X connect 1 0 2 0; -#X restore 110 329 pd \$0-test; -#X obj 28 22 inlet; -#X obj 71 141 list prepend obj 0 0; -#X obj 71 166 list trim; -#X obj 110 231 send pd-\$0-test; -#X obj 28 97 trigger anything anything bang; -#X obj 28 261 list prepend find; -#X obj 235 124 f \$0; -#X msg 262 93 bang; -#X obj 28 316 send \$0-in; -#X obj 28 345 r \$0-out; -#X msg 235 151 clear \, obj 200 20 receive \$1-in \, obj 200 60 canvasinfo -\, obj 200 100 send \$1-out \, connect 0 0 1 0 \, connect 1 0 2 0; -#X msg 28 370 list \$1; -#X obj 28 395 t b a; -#X obj 28 447 objectinfo; -#X msg 28 420 class; -#X obj 28 286 list trim; -#X text 63 53 for everything except receive \, send \, and canvasinfo -\, or comments; -#X obj 28 472 select text; -#X msg 28 497 0; -#X obj 102 497 b; -#X msg 102 522 1; -#X obj 28 559 outlet; -#X obj 71 191 unpost; -#X text 126 192 <- supress creation error message; -#X connect 2 0 6 0; -#X connect 3 0 4 0; -#X connect 4 0 24 0; -#X connect 6 0 7 0; -#X connect 6 1 3 0; -#X connect 6 2 8 0; -#X connect 7 0 17 0; -#X connect 8 0 12 0; -#X connect 9 0 8 0; -#X connect 11 0 13 0; -#X connect 12 0 5 0; -#X connect 13 0 14 0; -#X connect 14 0 16 0; -#X connect 14 1 15 1; -#X connect 15 0 19 0; -#X connect 16 0 15 0; -#X connect 17 0 10 0; -#X connect 19 0 20 0; -#X connect 19 1 21 0; -#X connect 20 0 23 0; -#X connect 21 0 22 0; -#X connect 22 0 23 0; -#X connect 24 1 5 0; +#X connect 2 0 3 0; +#X connect 2 1 4 0; +#X connect 3 0 6 0; +#X connect 4 0 5 0; +#X connect 5 0 6 0; diff --git a/scripts/utils/object-test.pd b/scripts/utils/object-test.pd new file mode 100644 index 0000000000000000000000000000000000000000..70308509056d3579d7b4f6e72b9f6333aedbc18a --- /dev/null +++ b/scripts/utils/object-test.pd @@ -0,0 +1,46 @@ +#N canvas 144 162 683 597 12; +#N canvas 82 171 450 346 \$0-test 0; +#X restore 110 329 pd \$0-test; +#X obj 28 22 inlet; +#X obj 71 141 list prepend obj 0 0; +#X obj 71 166 list trim; +#X obj 110 231 send pd-\$0-test; +#X obj 28 97 trigger anything anything bang; +#X obj 28 261 list prepend find; +#X obj 235 124 f \$0; +#X msg 262 93 bang; +#X obj 28 316 send \$0-in; +#X obj 28 345 r \$0-out; +#X msg 235 151 clear \, obj 200 20 receive \$1-in \, obj 200 60 canvasinfo +\, obj 200 100 send \$1-out \, connect 0 0 1 0 \, connect 1 0 2 0; +#X msg 28 370 list \$1; +#X obj 28 395 t b a; +#X obj 28 500 objectinfo; +#X obj 28 286 list trim; +#X text 63 53 for everything except receive \, send \, and canvasinfo +\, or comments; +#X obj 28 529 outlet; +#X obj 71 191 unpost; +#X text 126 192 <- supress creation error message; +#X obj 28 427 list append \$1; +#X text 97 22 Simple \, light wrapper around [objectinfo] methods; +#X obj 28 456 list trim; +#X connect 1 0 5 0; +#X connect 2 0 3 0; +#X connect 3 0 18 0; +#X connect 5 0 6 0; +#X connect 5 1 2 0; +#X connect 5 2 7 0; +#X connect 6 0 15 0; +#X connect 7 0 11 0; +#X connect 8 0 7 0; +#X connect 10 0 12 0; +#X connect 11 0 4 0; +#X connect 12 0 13 0; +#X connect 13 0 20 0; +#X connect 13 1 14 1; +#X connect 14 0 17 0; +#X connect 15 0 9 0; +#X connect 18 1 4 0; +#X connect 20 0 22 0; +#X connect 22 0 14 0;