PDA

View Full Version : Set if between values instruction



SeskaPeel
09-09-2003, 10:02 AM
I'm stuck in a fragment program trying to do something that should be quite easy. My head is just too messed to get out of it :

I want to set result to 1.0 if input value is between two others.
R = (Input >= S2 && Input < S1) ? 1.0 : 0.0

And it must be component wise

I just can't picture it ...

Thanks,
SeskaPeel.

[This message has been edited by SeskaPeel (edited 09-09-2003).]

SeskaPeel
09-09-2003, 10:22 AM
Actually this should work, but as I have to do it 4 times ... it becomes a bit expensive :




# Set to 1 if greater or equal
SGE Temp0, Input, S1 ;

# Set to 1 if lesser
SLT Temp1, Input, S2 ;

# Set to 1 if Temp0 == Temp1
SGE Temp2, -Temp0, -Temp1 ;
SGE Temp0, Temp0, Temp1 ;
MUL Result, Temp0, Temp2 ;


Any better solution ?

SeskaPeel.


[EDIT]
Found better ... (sorry for the flood of posts, I hope this last solution might please some of you)




SGE Temp0, Input, S1 ;
SLT Temp1, Input, S2 ;
MUL Result, Temp0, Temp1 ;


As Temp0 and Temp1 can be only 0 or 1, no need to perform a full equal ...

Sorry again
SeskaPeel.




[This message has been edited by SeskaPeel (edited 09-09-2003).]

ehart
09-09-2003, 10:36 AM
Why don't you implement the and as a simple multiply, or am I just missing something?

-Evan