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
truncating floats and weird trig results
5412 6 2- Henster
- Member
- 196 posts
- Joined: July 2005
- Offline
- Antoine Durr
- 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
- Henster
- Member
- 196 posts
- Joined: July 2005
- Offline
- deecue
- 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
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
- Antoine Durr
- Member
- 321 posts
- Joined: July 2005
- Offline
- asnowcappedromance
- 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
- Antoine Durr
- 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.
-
- Quick Links