04-07-2010 05:28 PM
Greetings,
Is it possible to cast a U32 to a SGL - an int32 to a float32 - inside a formula node? How?
Thanks!
04-07-2010 05:40 PM
You can declare a variable to be a certain type.
For example say x is an int32 input. Inside the formula node you can type 'float32 y=x' and you will have x casted to a float32 in the variable y.
04-07-2010 06:03 PM
Darin.K wrote:You can declare a variable to be a certain type.
For example say x is an int32 input. Inside the formula node you can type 'float32 y=x' and you will have x casted to a float32 in the variable y.
Hi Darin,
Thanks for the reply, though, what you suggested - float32 y = x; - is a simple assignment(?) If x is 2, the result is y will be 2(?)
In my case, x is the U32 (int32) result of a SGL being cast to a U32. I wanted to cast it back -- inside a formulat node(?)
Check out the "cast" function (Numeric\Conversion palette) to see what I mean.
After casting the SGL: 123.456 to a U32, it becomes: 0x42F6E979
I'd like to cast the 0x42F6E979 value back to 123.456 inside a formula node...
Thanks!
04-07-2010 07:10 PM
04-07-2010 08:07 PM
Well... we're just experimenting with the fastest way to unpack ~10,000 U32s into ~40,000 DBLs. The packed array is U32-aligned mixture of bit-mapped integers, bools, and floats - SGLs and DBLs. We've tried doing some "vector" (array) shift, mask and scale operations - which are pretty fast, but the float-unpacking seems to require a loop. After timing a For Loop structure, I wanted to push the for loop into a formula node - where I've hit a wall (without ability to cast) ...
Since the whole purpose of looking at formula node is to save time, I'm reluctant to roll my own "cast" function. ![]()
Thanks/Cheers!