Hi DImster
thanks for feedback and ideas to talk about.
I love this topic Tempodi
My pleasure to get the interest of QB64 coders.
The implied should be the value can be equal to min but not a value less than min. A value less than min should not be intheRange. If our range is 10 to 20 and the value is 9, that 9 would be less than the min of 10. ??? so what am I missing in this Logical Operator???
At the starting time, also I was thinking about
IMP as the word
imply but this is wrong and it brings us in the wrong direction. We use in human language this word with the meaning IF...THEN... while IMP seems to be a mathematical imply that formally has as name
Material Implication or
Material Conditional.
read here if you want to get more deep informations
https://en.wikipedia.org/wiki/Material_conditionalSo it seems that we must think about IMP as we think about + of the sum with its feature. It is an operator that gives False only if the first condition is True and the second condition is False. This is the path to set the right conditions in the two branches of IMP and to get back the desired result.
Well the function has the goal to return True (-1/ NOT 0) if the third parameter is between the first and the second parameters.
let's test the expression
intheRange = 0 '<---- this is the default result (False/ No)
intheRange
= (value
<= max
) IMP (value
<= min
) '<-- this is the expression that using IMP answer to the question " Is value between min and max? intheRange
= NOT intheRange
' <-- really the above expression calculates the OutOfRange so we must NOT the result
Min Max Value (value <= max) IMP (value <= min) (NOT (value<=max)) OR (value <=min)
10 20 9 (9<=20) IMP (9<=10) (NOT (9<=20)) OR (9<= 10)
True IMP True -------> True (NOT True) OR (True) ------> True
10 20 21 21 <= 20 IMP 21<= 10 NOT (21<=20) OR (21<= 10)
False IMP False ---> True NOT False OR False ------> True
10 20 11 11<= 20 IMP 11<=10 NOT(11<=20) OR (11<=10)
True IMP False ---> False NOT True OR False -----> False
changing the > with < and viceversa we get the one shot InTheRange
Min Max Value (value >= max) IMP (value >= min) (NOT (value>=max)) OR (value >=min)
10 20 9 (9>=20) IMP (9>=10) (NOT (9>=20)) OR (9>= 10)
False IMP False -------> True (NOT False) OR (False) ------> True
10 20 21 21 >= 20 IMP 21>= 10 NOT (21>=20) OR (21>= 10)
True IMP True ---> True NOT True OR True ------> True
10 20 11 11>= 20 IMP 11>=10 NOT(11>=20) OR (11>=10)
False IMP True ---> True NOT False OR True -----> True
So the code of the FUNCTION InTheRange will be
intheRange = 0 '<---- this is the default result (False/ No)
intheRange
= (value
>= max
) IMP (value
>= min
) '<-- this is the expression that using IMP answer to the question " Is value between min and max?
And with this last sentence I feel to have finished to share my new knowledge about IMP.
PS Thank you, I have got a new InTheRange in oneshot!
Now I'll try to give an universal wellworking also with negative numbers. Next time.