03-23-2010 04:21 PM
Hi all,
Please take a look at the code and tell me does the code contain too many nested if? It is not done yet, but it is supposed to be a subvi that convert one type of floating point format to another type. There are many exceptions that I need to check. Also, I am converting from c to labview, so in c the program has a lot of if, elseif, else, etc in it.
Should I make it a state machine instead? However, it seems slower to do a state machine. Please give me some sugestion.
Also, how do I make all the condition more obvious? Since all the case structures are nested, it is hard to see the big picture unlike text base.
Yik
03-23-2010 04:26 PM
03-23-2010 05:23 PM
Could you give a link describing the TI FP specs?
You only need to deal with the "exceptions". You can build an array of the various booleans and convert it to a number. Now use a case structure and wire the number to it. Set the radix of the case display to binary and add as many unique cases as you need. Use the default case for the bulk of the work.
03-23-2010 05:25 PM
If this is a piece of code that is going into a tight loop to be executed many times I would consider sticking to nested case statements. Keep things tidy and it is not difficult to follow. What I would do, however, is bag all of those comparisons outside the case statements and just wire the value directly. =0? becomes a case structure with two cases 0,Default. Same for other cases. Be sure to show the radix for the case display and it is neatly documented as well. When I am porting C code, I typically use the code I am replicating as a free label, one case may get if (x==0) another gets else and so on.
If the code will be used at a leisurely pace, you won't notice the performance hit that you will take by going to a state machine. It would be easier to add cases later, but this sounds like a well-formed problem so that may not be a consideration.
At any rate, if your code starts to look like this, then please go to a state machine else I would go with whatever feels intuitive to you.
03-23-2010 07:39 PM
Hi all,
I have attached the c code that I am trying to convert (starting on page 71). I ended up using the state machine. I created a case for each condition, and inside these cases, I would do my condition check. I ended up having to use a case structure inside each case. Not sure is that the best way or not. I should be able to post some code up for review tomorrow.
Yik
03-24-2010 10:23 AM
Attached is my state machine. Please take a look to see can I simplify it or make it better.
Yik
03-24-2010 11:01 AM
Looking at your picture one extra time, it looks like you're checking if a Single is a special case of sorts (as +/- inf), if that's the case you can simply do a comparison with the the Inf-constant (and the others) from the numeric pallette.
/Y