integer precision only 8 bit?

   3119   5   1
User Avatar
Member
380 posts
Joined: July 2005
Offline
In trying to get some timing information I was surprised to
find that subtracting two 10 digit integers failed to produce
the expected result. Is there a way to get houdini expressions
to evaluate big ints correctly?


/ -> set START = `system(“date +%s”)`
/ -> echo $START
1287171710
/ -> set END = `system(“date +%s”)`
/ -> echo $END
1287171723
/ -> echo `eval($START)`
1.28717e+09
/ -> echo `eval($END)`
1.28717e+09
/ -> echo `$END - $START`
0
/ -> echo `system(“echo $END - $START | bc”)`
13
User Avatar
Staff
2592 posts
Joined: July 2005
Offline
sdugaro
In trying to get some timing information I was surprised to
find that subtracting two 10 digit integers failed to produce
the expected result. Is there a way to get houdini expressions
to evaluate big ints correctly?


/ -> set START = `system(“date +%s”)`
/ -> echo $START
1287171710
/ -> set END = `system(“date +%s”)`
/ -> echo $END
1287171723
/ -> echo `eval($START)`
1.28717e+09
/ -> echo `eval($END)`
1.28717e+09
/ -> echo `$END - $START`
0
/ -> echo `system(“echo $END - $START | bc”)`
13

Houdini expressions don't have an integer type. You can always do something like:

/ -> set START = `system(“date +%s”)`
/ -> set END = `system(“date +%s”)`
/ -> echo `pythonexprf(“$END - $START”)`
5

though if you want long integer arithmetic. Of course, you could also just use Python. This example stores the time as a string rather than a float to get Python's precision out…

/ -> set START = `pythonexprs(“__import__('time').time()”)`
/ -> set END = `pythonexprs(“__import__('time').time()”)`
/ -> echo $START, $END, `$END-$START`
1287173486.81, 1287173492.75, 5.94
/ ->
User Avatar
Member
4262 posts
Joined: July 2005
Offline
As far as I know, Houdini's expression language doesn't even have a int type. Its all floats under the hood.

Do the work in Python instead?



curse you mark. beat me by a minute
if(coffees<2,round(float),float)
User Avatar
Member
380 posts
Joined: July 2005
Offline
perfect, thanks! 8)
User Avatar
Member
380 posts
Joined: July 2005
Offline
Hmm, thought to inline and format… any idea why this fails?


/ -> set START = `pythonexprs(“__import__('time').time()”)`
/ -> set END = `pythonexprs(“__import__('time').time()”)`
/ -> echo `pythonexprs(“$END - $START”)`
4.74000000954
/ -> echo `pythonexprs(“'%.3f'%($END - $START)”)`
File <stdin>, line 1 %.3f%(1287177562.79 - 1287177558.05) ^ SyntaxError: invalid syntax
/ -> echo `pythonexprs(“__import__('time').time() - $START”)`
Traceback (most recent call last): File <stdin>, line 1, in <module> NameError: name time is not defined
/ -> echo `pythonexprs(“'%.3f'%(12.34567890 - 2.345)”)`
10.001
User Avatar
Member
380 posts
Joined: July 2005
Offline
seems like the vars need to be expanded out into a string before they can be used in pythonexprs…


/ -> echo $str
'%.3f'%(__import__('time').time() - 1287177558.05)
/ -> echo `pythonexprs($str)`
1432.797
  • Quick Links