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);