Jump to content
DeeLan

VEX Modulo Operation giving incorrect results

Recommended Posts

I've got a Wrangle Node (set to Detail) with some stuff in it. Amount that is a simple Modulo Operation - "offset%spacing". Now obviously if offset is a multiple of spacing then "offset%spacing" should equal 0. Problem is, most of the time it definitely does not equal zero. I've found that when spacing equals certain values (0.5 for example) then the result is as it should be. However most of the time I'm getting errors. Some are small (2.08616e-07 is one such value) but others have been as big as "spacing" itself. For example, at the moment offset and spacing are 27.6 and 0.4 respectively. When I put those values through a calculator I get 0 (as I should, because 27.6 is a multiple of 0.4). However Houdini simply gives me 0.4 I've gone a done the math by hand (well really by calculator) for a bunch of combinations and while they all return 0, Houdini still gives an incorrect value.

Please Help! I have absolutely no idea why this is happening.

Share this post


Link to post
Share on other sites

I would round the offset value before modulo operation OR multiply the offset and transform to integer like this:

int(offset*10)%4

Share this post


Link to post
Share on other sites

That's a great works perfectly :) Thanks! Do you know if there's a particular reason as to why it works properly with integers and not decimals? Or is just "One of those things"?

Share this post


Link to post
Share on other sites

I think it's a problem of precision. Transform in integer avoid this precision. It's why round the offset must works too. ;)

Share this post


Link to post
Share on other sites

so I'm still getting issues even when I convert to integers. Its really weird, but I'm finding the only way to only way to get the correct results is to decrease the accuracy. For example, if I multiply (and then redivide) my float by anything above 10^5, then I get incorrect results again, whereas 10^4 seems to get it right all the time (so far). So even if I have a value to 6 or 7 decimal places, its better to just multiply by 10^4 and lose those last few digits. Its just so odd that using less accurate values yields the proper results.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×