Can't Divide @numpt by @ptnum?

   4539   4   0
User Avatar
Member
240 posts
Joined: April 2014
Offline
Windows 10
Houdini 17.5.360

f@ratio = @ptnum/@numpt;

This should give me a ratio, but instead results in 0 for all my points. Same in VOPs. Why is that? Does it error out when trying to divide by zero?

I can use a fit function as seen below as a temporary workaround…



Thanks,
Luke



Edited by Luke Letellier - Sept. 23, 2019 11:53:14

Attachments:
Letellier_PtRatio_Debug.hiplc (139.2 KB)

User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
hi, probably you need to convert them to float values before the operation
User Avatar
Member
37 posts
Joined: Aug. 2015
Offline
Yes like Andr says, you are dividing two integers and the result is a fraction. Since integers have no fractional part the result is truncated to 0. (If i remember correctly the dotted line in VOPs denotes an implicit type cast)
User Avatar
Member
2038 posts
Joined: Sept. 2015
Online
…and you only need to have one value as a float:

f@ratio = (@ptnum*1.0)/@numpt;
f@ratio = @ptnum/(@numpt*1.0);
f@ratio = @ptnum/float(@numpt);
f@ratio = float(@ptnum)/@numpt;
Edited by BabaJ - Sept. 24, 2019 10:18:21
User Avatar
Member
8539 posts
Joined: July 2007
Online
most of the times however you want something like this
f@ratio = @ptnum/(@numpt - 1.0);
to get values in full range from 0 to 1
Tomas Slancik
FX Supervisor
Method Studios, NY
  • Quick Links