truncating floats and weird trig results

   5155   6   2
User Avatar
Member
196 posts
Joined: July 2005
Offline
Hi,

I'm doing something like this:

atan($X/$Y)

and I'm getting weird results. I've found an example of what is causing it. A number like this crops up 1.61499e-00 (from the geometry spreadsheet). If I then rig this same calculation but exchange this number for a truncated version 1.61499 then it works.

I cant find a function that truncatesto a few floating points???

Thanks for any replies
Henster
User Avatar
Member
321 posts
Joined: July 2005
Offline
Henster
Hi,

I'm doing something like this:

atan($X/$Y)

and I'm getting weird results. I've found an example of what is causing it. A number like this crops up 1.61499e-00 (from the geometry spreadsheet). If I then rig this same calculation but exchange this number for a truncated version 1.61499 then it works.

I cant find a function that truncatesto a few floating points???

Thanks for any replies

First of all, the geo spreadsheet probably truncates what you see, so you probably shouldn't use it to really gauge this. Instead, write out a .geo file and look at the values in there.

That said, the Houdini math libraries have (since the PRISMS) days had problems with really, really small numbers. I would add in (via a point SOP) something like if(abs($TX)<.00001,0, $TX), i.e. knock all near-zero values down to zero.

– Antoine
Antoine Durr
Floq FX
antoine@floqfx.com
_________________
User Avatar
Member
196 posts
Joined: July 2005
Offline
These values are in pops so I dont think they'll show up in a geo file.

Using the if((abs($TX)<0.0001,0,$TX) thing only truncates numbers that are close to zero. It looks like the problems are coming just when there are loads of decimal places.
Henster
User Avatar
Member
412 posts
Joined: July 2005
Offline
if you're wanting to just truncate the number of decimal places, here's an odd way of doing it:

rint(val*10^n)*10^(-n)

where n is the number of decimal places you want.


so say you wanted to truncate a value to 3 decimal places..

Value: 3.4832165132165132158

rint(3.4832165132165132158*1000)*.001
= rint(3483.2165132165132158)*.001
= 3483*.001
= 3.483

put in your expression for val and it should work. can make some interesting step curves as well depending on the number of decimal places you allow for.

hth,
dave
Dave Quirus
User Avatar
Member
321 posts
Joined: July 2005
Offline
Henster
These values are in pops so I dont think they'll show up in a geo file.

If you set the cook/display flag to the node where you found your suspected problem, write out the .geo from the popnet SOP.

– Antoine
Antoine Durr
Floq FX
antoine@floqfx.com
_________________
User Avatar
Member
512 posts
Joined: July 2009
Offline
deecue
if you're wanting to just truncate the number of decimal places, here's an odd way of doing it:

rint(val*10^n)*10^(-n)

where n is the number of decimal places you want.


so say you wanted to truncate a value to 3 decimal places..

Value: 3.4832165132165132158

rint(3.4832165132165132158*1000)*.001
= rint(3483.2165132165132158)*.001
= 3483*.001
= 3.483

put in your expression for val and it should work. can make some interesting step curves as well depending on the number of decimal places you allow for.

hth,
dave

hi,

very interesting topic,

but is there really no other way of truncating decimal places via expressions???

regards,

Manu
http://vimeo.com/user2522760 [vimeo.com]
http://stormbornvfx.com/ [stormbornvfx.com]
Manuel Tausch
User Avatar
Member
321 posts
Joined: July 2005
Offline
asnowcappedromance
very interesting topic,

but is there really no other way of truncating decimal places via expressions???

Not as far as I know. The truncation of decimal places is not a feature of floating point values as represented internally in the computer. Internally, the value 1 is actually 1.00000 (with however many decimal points allowed by the particular float/double representation).

The age-old approach is to truncate on printing. The C stdio library has a bunch of options to it's printf() function. I don't have H in front of me, so I don't know to what extent the %f or %g options are implemented. In C, you can print %.2f, which will show the value 1 as 1.00, or %g which will show 1.23000 automatically as 1.23.
Antoine Durr
Floq FX
antoine@floqfx.com
_________________
  • Quick Links