Multiplying @ptnum by 0 gives the value 0 once...

   1080   3   0
User Avatar
Member
143 posts
Joined: May 2017
Offline
Hi folks,

is there any explanation why multiplying @ptnum by 0 gives 0 - it is executed only once, even if multiple points are involved.

For example, a Point Wrangle with 3 points:

printf("%i \n", @ptnum * 0); 	// 0
printf("%i \n", @ptnum); 	// 0, 1, 2

Is a kind of optimization?

Another example with modulo and 6 points gives a correct result:
printf("%i \n", @ptnum * (@ptnum % 2)); // 0, 1, 0, 3, 0, 5
Edited by viklc - Sept. 25, 2022 06:17:30
User Avatar
Member
8514 posts
Joined: July 2007
Online
Purely based on experience (without understanding precise details of SIMD execution) I'd say yes, it's an optimization

And my experience so far has been that any expression that at compile time can be guaranteed to return the same value for all elements will be executed/printed only once as the value is gonna be the same for all (as there is no need to run something 100million times if you already know all will be 0 or any other constant value)
Edited by tamte - Sept. 25, 2022 08:05:30
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
427 posts
Joined: Aug. 2019
Offline
It's not a valid optimization tho (if you can call it that). printf() has side effect and no proper compiler should merge several printf() calls into one like that. It's only a valid optimization for pure functions.

I'd say to file a bug report.
Edited by raincole - Sept. 25, 2022 09:52:57
User Avatar
Member
143 posts
Joined: May 2017
Offline
I will forward this as a bug report. Thank you both.
  • Quick Links