Exemple #1
0
 public static ushort gxPerm(ushort n, ushort k)
 {
     return(Support.permutation_nbits(n, k));
 }
Exemple #2
0
        public void Parse(char[] fmt)
        {
            num.Clear();
            stack.Clear();
            try
            {
                foreach (char ch in fmt)
                {
                    switch (ch)
                    {
                    /////////////// basic types
                    case char n when numbers.Contains(ch):
                        num.Extend(n);

                        break;

                    case '.':     // set fracpart
                        num.ConvertFrac();
                        break;

                    case '-':     // negate
                        num.Negate();
                        break;

                    case ',':     // save arg
                        PushNum();
                        num.Clear();
                        break;

                    /////////////// higher level types
                    case 'n':     // nil field
                        states[col].fmt       = 'n';
                        states[col].bit_width = 0;
                        states[col].bit_mask  = 0;
                        num.Clear();
                        break;

                    case 'b':     // bits as integer: b,<bitlength>
                        states[col].fmt       = (stack.Count == 0) ? 'b' : 'e';
                        states[col].bit_width = num.ExtractUInt();
                        states[col].bit_mask  = (uint)(1 << (int)states[col].bit_width) - 1;
                        num.Clear();
                        break;

                    case 'f':                                          // float: f,<offset>,<stepsize>,<stepcount>
                        states[col].fmt          = (stack.Count == 2) ? 'f' : 'e';
                        states[col].float_offset = num.ExtractFloat(); // arg1
                        states[col].float_step   = PopFloat();         // arg2
                        states[col].float_count  = PopUInt();          // arg3
                        states[col].bit_width    = Support.count_nbits(states[col].float_count);
                        states[col].bit_mask     = (ulong)(1 << (int)states[col].bit_width) - 1;
                        num.Clear();
                        break;

                    case 'p':                                       // permutation: p,<n>,<k>,<group>,<pick>
                        states[col].fmt        = (stack.Count == 3) ? 'p' : 'e';
                        states[col].perm_n     = num.ExtractUInt(); // arg1
                        states[col].perm_k     = PopUInt();         // arg2;
                        states[col].perm_group = PopUInt();         // arg3;
                        states[col].perm_pick  = PopUInt();         // arg4;
                        states[col].bit_width  = Support.permutation_nbits(states[col].perm_n, states[col].perm_k);
                        states[col].bit_mask   = (ulong)(1 << (int)states[col].bit_width) - 1;
                        num.Clear();
                        break;
                    }
                }
            }
            catch
            {
                states[col].fmt = 'e'; // err
            }
            col++;
        }