"divide by scalar" and precision problems

Discussions about SOFTIMAGEs© Interactive Creative Environment©
jipo
Posts: 13
Joined: 22 Jun 2011, 07:23

"divide by scalar" and precision problems

Post by jipo » 15 Jan 2014, 20:36

Hi,

I was haunting one strange problem with my compounds, that worked fine, but for some isolated combination of value everything was broken.
It was a strange ride, but i reduced the problem to the simplest form and i am asking you if you find it correct or not.

I am doing an integer division. there is not a direct node for it, so i have a compound that converts integer to scalar and uses "divide by scalar" .the result is later
used to return both division and "modulo".

the problem is the conversion int->scalar. because of the precision for some numbers A div A is 0 as you can see on the attached screenshot.
i was expecting precision problems for bigger numbers....

so,what is the most elegant way to compute integer division (with a remainder - if it is correct english term for it) ? :-)
You do not have the required permissions to view the files attached to this post.

User avatar
xsisupport
Posts: 713
Joined: 09 Jun 2009, 09:02
Location: Montreal Canada

Re: "divide by scalar" and precision problems

Post by xsisupport » 15 Jan 2014, 21:32

You're always going to get the floor when you let the nodes do the implicit conversion to integer.
Work with scalars and then at the end decide whether to round or floor.
Here's an example Integer Division compound by Guillaume Laforge:
http://screencast.com/t/he5KwoDElvC
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs: Arnold | Softimage