Sometimes when I type a value into a field, like 2, it turns into 2.000000000001. I understand there is a limit to the number of digits in floating point number but I am just typing an number without any calculations. I am curious about reason behind this.
The only time I found this a problem was when I was trying to find out points with certain u value “0.7382”, which was shown on the geometry spreadsheet. I was just using an “if” statement to check if the value was exactly equals to “0.7382” but it returns nothing. I later suspected that there were some digits hidden behind it so I multiplied it by 10000 then converted it to integer for comparison and it worked. Does anyone got a better way to compare values?
Why are values inaccurate in Houdini?
4725 8 1- benC
- Member
- 49 posts
- Joined: 2月 2016
- Offline
- protozoan
- Member
- 1718 posts
- Joined: 3月 2009
- Offline
- SteN
- Member
- 55 posts
- Joined: 3月 2015
- Offline
benCNever, never do that, never try to compare two float to see if they are equal: it will never work.
I was just using an “if” statement to check if the value was exactly equals to “0.7382” but it returns nothing.
I had the same problem (see here [sidefx.com]) and what you have to do instead is compare a value (the value you are looking for) to a range, with your example you can write the following code:
if(value > 0.73 && value < 0.74) { //Do stuff }
Or also:
float _tolerance = 0.01; if( (value - 0.7834) <= _tolerance) { //Do stuff }
So basically to get that to work you dont check if the two values are equal, but if the two values are more or less close
Edited by SteN - 2017年4月18日 09:53:15
- BabaJ
- Member
- 2129 posts
- Joined: 9月 2015
- Offline
Also,…it's not a Houdini ‘thing’. It's with how hardware treats ‘floats’.
This link is but once example of the topic and you may want to do some of your own searches to get a better understaning:
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html [docs.oracle.com]
When you have a better understanding, then you will be able to write the code in a way that serves your purpose like the suggestion SteN gave.
This link is but once example of the topic and you may want to do some of your own searches to get a better understaning:
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html [docs.oracle.com]
When you have a better understanding, then you will be able to write the code in a way that serves your purpose like the suggestion SteN gave.
- benC
- Member
- 49 posts
- Joined: 2月 2016
- Offline
- benC
- Member
- 49 posts
- Joined: 2月 2016
- Offline
It was working when I use blast @uv==0.7382 to isolate the points but not "if(@uv==0.7382)" in attribute wrangle. Anyone know the reason behind this?
- edward
- Member
- 7899 posts
- Joined: 7月 2005
- Offline
- jsmack
- Member
- 8043 posts
- Joined: 9月 2011
- Offline
- mtucker
- スタッフ
- 4525 posts
- Joined: 7月 2005
- Offline
-
- Quick Links