# Thread: is there an equation that will return 1 for a certain number and 0 for anything else?

1. ## is there an equation that will return 1 for a certain number and 0 for anything else?

is there an equation that will return 1 for a certain number and 0 for anything else? So, say I want to test whether some value is equal to 47, but I want to be able to do it right inside an expression, rather than as a separate condition - is there some way to make an equation turn 47 into 1, while any other number will result in 0? Perhaps using one of the bitwise operators or something?

I've been using the Immediate If object for this (ie. to squeeze a condition inside an expression) but if there's a mathematical and extension-less way I think I'd prefer to use that.

2. Code:
`Floor(( 2.7183 pow ( -1 * ( ( Value - 47 ) pow 2 ) ) ))`
Normal distribution.

3. Originally Posted by defisym
Code:
`Floor(( 2.7183 pow ( -1 * ( ( Value - 47 ) pow 2 ) ) ))`
Normal distribution.
Whoa this is cool - is 2.7183 a constant that works for every value or did you derive it from the target 47 somehow

edit: ah, that's eulers number. woops, been a couple decades since I last looked at it and wondered why it was familiar

4. Or, you can use the following if you only use integers:
Abs(Min(Abs(Value - 47),1)-1)

5. Looks like you got your answer. So yo, Vol - how is Spryke coming along? Would be cool to hear the latest on it!

6. Originally Posted by defisym
Code:
`Floor(( 2.7183 pow ( -1 * ( ( Value - 47 ) pow 2 ) ) ))`
Normal distribution.
That's like magic

I don't trust myself to remember to type it correctly though. But seeing this gave me some ideas of slightly simpler ways of doing it. Seeing you use pow got me thinking in that direction, and I thought this might get me there:

Code:
`( Value - 47 ) pow 0`
In Excel, this returns 1 for all wrong numbers, and a #num error for the right number. I hoped that in Fusion it would simply return a 0 for the right number. Though actually just returns 1 for everything. But I ended up with this, which is still relatively short (and will be easier for me to remember than the Euler's number-based one):

Code:
`( ( Value - 47 ) / ( Value - 47 ) ) xor 1`
If the number is correct (47) it will produce a divide-by-zero scenario, which Fusion graciously turns into an error-free zero. That gives 1 for all the wrong numbers, and 0 for the right one. The XOR 1 then flips that around, so all the 1s become 0s and 0 becomes 1.

Thanks for your help, guys

@Progject : I started answering your question about Spryke, but eventually turned it into its own post on the Spryke thread

7. @Volnaiskra try Max(1 - Abs(Value A - Value B), 0). If A = B it returns 1, else 0. Works for all decimal places.

8. Originally Posted by Volnaiskra
Code:
`( ( Value - 47 ) / ( Value - 47 ) ) xor 1`
If the number is correct (47) it will produce a divide-by-zero scenario, which Fusion graciously turns into an error-free zero. That gives 1 for all the wrong numbers, and 0 for the right one. The XOR 1 then flips that around, so all the 1s become 0s and 0 becomes 1.
If you'd like to get rid of the brackets, this also pretty much does the same thing:
Code:
`(1 - a xor b / a xor b)`
Operations in order:
- Highest priority: xor gives 0 if both left and right values are the same.
- Second highest: division gives 1 if both left and right values are the same except for 0.
- Last: subtraction inverses the result so that equality is 1 and inequality is 0.

where a and b are your values that you want to check for equality.

9. Thanks BartekB! I definitely appreciate having fewer brackets. Many of my expressions are complicated enough already, without adding another bunch of brackets to make it even harder to follow. I love that your solution is self-contained in a single set of brackets. I'll use this formula for sure.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•