i have constants that represents a prime number. for example,
enum Signals : long
{
LONGPULLBACK = 2,
SHORTPULLBACK = 3,
RSIOVERSOLD = 5,
RSIOVERBOUGHT = 7,
BOUGHTSIGNAL = 9,
DOUBLEBOUGHTSIGNAL = 11,
SOLDSIGNAL = 13,
DOUBLESOLDSIGNAL = 17,
MATRENDINGLONG = 19,
MATRADENINGSHORT = 23
}
for every signal triggered, i just add it to the sum. there will always be only 1 signal of each type triggered. when i have a sum of 25, is there a function to return the prime number parts of the sum ie 2,23?
No.
But you can achieve what you want by using flags. Just don't use 0 as one of your flags for one of the values in your list. 0 can only denote None because you'll never be able to check whether a 0 was added. And the values must be powers of 2. So: 1, 2, 4, 8, ... And only up to 63 values (besides the 0) if you're using long
to account for the sign bit. I think you can get 64 if you're using ulong
.
Example:
[Flags]
enum Signals : long
{
None = 0,
LONGPULLBACK = 1,
SHORTPULLBACK = 2,
RSIOVERSOLD = 4,
RSIOVERBOUGHT = 8,
//etc.
};
(I'll add that what you were trying to do would work if you were multiplying the numbers. But that would make the number pretty big. Also, decomposition wouldn't be as simple.)