LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

casting inside a "formula node"

Greetings,

      Is it possible to cast a U32 to a SGL - an int32 to a float32 - inside a formula node?  How?

 

Thanks!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 1 of 5
(4,982 Views)

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.

 

0 Kudos
Message 2 of 5
(4,977 Views)

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!

 

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 3 of 5
(4,968 Views)
I fell into a bad habit of interchanging casts with coercions (or conversions).  You are one of the few who actually would like an honest-to-goodness cast.  I don't think that is a suppoprted function in the formula node so you could either roll-your-own with some bit-shifting or abandon the formula node.  Is there a particular reason you are attached to the formula node?
0 Kudos
Message 4 of 5
(4,958 Views)
Re: Is there a particular reason you are attached to the formula node?

 

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. Smiley Wink

 

Thanks/Cheers!

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 5 of 5
(4,949 Views)