09-23-2013 01:47 PM
Hi,
Could you please let me know how can I implemet this logic
if 2.39<x<2.4 then y=4.8
if 2.42<x<2.45 then y=5.0
if 2.47<x<2.50 then y=5.2
.
.
.
All the values are hard coded
Thanks
09-23-2013 01:49 PM
As usual, show us what you got. 🙂
09-23-2013 02:00 PM
And what if x <= 2.39?
2.4 <= x <=2 .42?
2.45 <= x <=2 .47?
Or x >= 2.50?
There are holes in your ranges.
09-23-2013 02:04 PM
Then the value is invalid,
it should be actually like this
2.39<=x<=2.4 then y=4.8
2.42<=x<=2.45 then y=5
.
.
09-23-2013 02:08 PM - edited 09-23-2013 02:08 PM
I would multiply the value by 100 then wire that into a case structure selector terminal.
The case structure would have 4 cases defined.
239 .. 240 it outputs a 4.8 to the tunnel
242 .. 245 it outputs a 5.0 to the tunnel
247 .. 250 it outputs a 5.2 to the tunnel
Default it outputs a 0 or some other value that you define that you want to represent as an invalid value.
09-23-2013 04:25 PM
You could use a formula node from the Structures menu. It uses expressions similar to C.
09-23-2013 10:03 PM
Multiplying by 100 and then comparing integer is always better then comparing floating value. Opt for 'X100'
09-24-2013 10:51 AM
@Ranjeet_Singh wrote:
Multiplying by 100 and then comparing integer is always better then comparing floating value. Opt for 'X100'
So... what happens if the number has three decimal places? 😉
More correctly stated, I guess you could say "multiply the numbers to be compared by 10^x, where x equals the precision of your most precise number.
09-24-2013 11:31 AM
@billko wrote:
@Ranjeet_Singh wrote:
Multiplying by 100 and then comparing integer is always better then comparing floating value. Opt for 'X100'
So... what happens if the number has three decimal places? 😉
More correctly stated, I guess you could say "multiply the numbers to be compared by 10^x, where x equals the precision of your most precise number.
This is an excellent point. Given the example, multiply by 100 would work fine. But you also need to be aware of rounding, which is a whole other issue you probably don't want to think about. When converting to an integer, the number will round toward 0.
09-24-2013 11:45 AM
@crossrulz wrote:
@billko wrote:
@Ranjeet_Singh wrote:
Multiplying by 100 and then comparing integer is always better then comparing floating value. Opt for 'X100'
So... what happens if the number has three decimal places? 😉
More correctly stated, I guess you could say "multiply the numbers to be compared by 10^x, where x equals the precision of your most precise number.
This is an excellent point. Given the example, multiply by 100 would work fine. But you also need to be aware of rounding, which is a whole other issue you probably don't want to think about. When converting to an integer, the number will round toward 0.
But by multiplying as I have shown, that should result in all numbers being integers... or are you saying that if you specified 0.5 was internally represented as 0.499 you are in danger of coming up with 4 as your integer, not 5?