TLC123 wrote
> Thanks
> ```function prod(v) = exp([for(i=v) ln(i)]* [for(i=v) 1]);```
> Sure does satisfy neat if not speed. :)
I've done tons of timing tests on OpenSCAD code and I'm pretty sure this is
the fastest way to compute a product. The question is whether you care
about speed, actually. Also, how long is your list? Because products of
long lists are either zero or infinity unless they are very specially formed
lists.
I did a quick time test against the recursive approach to demonstrate this
(and I'm not at all surprised to see that this code is about 4-6 times
faster than the recursive approach):
On length 100k lists:
recursive method: 450 ms
log method: 80ms
On length 1000 lists:
recursive: 4ms
log method: 0.8 ms
length 10 lists:
recursive: 50 microseconds
log method: 12 microseconds
The real issue I see with this code is accuracy and of course the inability
to handle inputs less than zero. It can produce non-integer output for
integer input, for example. (Note, it appears that exp(log(0))=0. Does
that always work?)
--
Sent from:
http://forum.openscad.org/_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org