// Modifier to apply to the field value. It can be one of: none, log, log1p,
// log2p, ln, ln1p, ln2p, square, sqrt, or reciprocal. Defaults to: none.
321161
func (fn *FieldValueFactorFunction) Modifier(modifier string) *FieldValueFactorFunction {
	fn.modifier = modifier
	return fn
}
718973
func sqrtMod(x *big.Int, p *big.Int) (z *big.Int) {
	/* assert that p % 4 == 3 */
	if new(big.Int).Mod(p, big.NewInt(4)).Cmp(big.NewInt(3)) != 0 {
		panic("p is not equal to 3 mod 4!")
	}

	/* z = sqrt(x) % p = x^((p+1)/4) % p */

	/* e = (p+1)/4 */
	e := new(big.Int).Add(p, big.NewInt(1))
	e = e.Rsh(e, 2)

	z = expMod(x, e, p)
	return z
}
666996
func (cfg *Config) Apply(opts ...Option) error {
	for _, opt := range opts {
		if opt == nil {
			continue
		}
		if err := opt(cfg); err != nil {
			return err
		}
	}
	return nil
}
628528
func (dt *DbfTable) SetFieldValue(row int, fieldIndex int, value string) (err error) {

	b := []byte(dt.encoder.ConvertString(value))

	fieldLength := int(dt.fields[fieldIndex].length)

	//DEBUG

	//fmt.Printf("dt.numberOfBytesInHeader=%v\n\n", dt.numberOfBytesInHeader)
	//fmt.Printf("dt.lengthOfEachRecord=%v\n\n", dt.lengthOfEachRecord)

	// locate the offset of the field in DbfTable dataStore
	offset := int(dt.numberOfBytesInHeader)
	lengthOfRecord := int(dt.lengthOfEachRecord)

	offset = offset + (row * lengthOfRecord)

	recordOffset := 1

	for i := 0; i < len(dt.fields); i++ {
		if i == fieldIndex {
			break
		} else {
			recordOffset += int(dt.fields[i].length)
		}
	}

	dt.fillFieldWithBlanks(fieldLength, offset, recordOffset)

	// write new value
	switch dt.fields[fieldIndex].fieldType {
	case Character, Logical, Date:
		for i := 0; i < len(b) && i < fieldLength; i++ {
			dt.dataStore[offset+recordOffset+i] = b[i]
		}
	case Float, Numeric:
		for i := 0; i < fieldLength; i++ {
			// fmt.Printf("i:%v\n", i)
			if i < len(b) {
				dt.dataStore[offset+recordOffset+(fieldLength-i-1)] = b[(len(b)-1)-i]
			} else {
				break
			}
		}
	}

	return

	//fmt.Printf("field value:%#v\n", []byte(value))
	//fmt.Printf("field index:%#v\n", fieldIndex)
	//fmt.Printf("field fixedFieldLength:%v\n", dt.Fields[fieldIndex].fixedFieldLength)
	//fmt.Printf("string to byte:%#v\n", b)
}
503226
func (prod *SimpleProducer) Modulate(msg *Message) ModulateResult {
	if len(prod.modulators) > 0 {
		msg.FreezeOriginal()
		return prod.modulators.Modulate(msg)
	}
	return ModulateResultContinue
}
622351
func (fn *GaussDecayFunction) FieldName(fieldName string) *GaussDecayFunction {
	fn.fieldName = fieldName
	return fn
}
1312037
func (c C) Moddif(y, mod Input) Input {
	var (
		diff    = c.Absdif(y).Modulo(mod)
		modhalf = mod.Mul(C(0.5))
	)
	return modhalf.Add(diff.Absdif(modhalf).Neg())
}
1085055
func (reader PluginConfigReaderWithError) GetModulatorArray(key string, logger logrus.FieldLogger,
	defaultValue ModulatorArray) (ModulatorArray, error) {
	modulators := []Modulator{}

	modPlugins, err := reader.GetPluginArray(key, []Plugin{})
	if err != nil {
		return modulators, err
	}
	if len(modPlugins) == 0 {
		return modulators, nil
	}

	errors := tgo.NewErrorStack()
	errors.SetFormat(tgo.ErrorStackFormatCSV)

	for _, plugin := range modPlugins {
		if filter, isFilter := plugin.(Filter); isFilter {
			filterModulator := NewFilterModulator(filter)
			modulators = append(modulators, filterModulator)
		} else if formatter, isFormatter := plugin.(Formatter); isFormatter {
			formatterModulator := NewFormatterModulator(formatter)
			modulators = append(modulators, formatterModulator)
		} else if modulator, isModulator := plugin.(Modulator); isModulator {
			if modulator, isScopedModulator := plugin.(ScopedModulator); isScopedModulator {
				modulator.SetLogger(logger)
			}
			modulators = append(modulators, modulator)
		} else {
			errors.Pushf("Plugin '%T' is not a valid modulator", plugin)
			panic(errors.Top())
		}
	}

	return modulators, errors.OrNil()
}
960714
func SetField(src interface{}, v reflect.Value, fieldName string) error {
	field := v.FieldByName(fieldName)
	if !field.IsValid() {
		return fmt.Errorf("couldn't find %v field in %T", fieldName, v.Interface())
	}
	srcValue := reflect.ValueOf(src)
	if srcValue.Type().AssignableTo(field.Type()) {
		field.Set(srcValue)
		return nil
	}
	if srcValue.Type().ConvertibleTo(field.Type()) {
		field.Set(srcValue.Convert(field.Type()))
		return nil
	}
	return fmt.Errorf("couldn't assign/convert %v to %v", srcValue.Type(), field.Type())
}
1157018
func (d *Datum) SetValue(val interface{}) {
	switch x := val.(type) {
	case nil:
		d.SetNull()
	case bool:
		if x {
			d.SetInt64(1)
		} else {
			d.SetInt64(0)
		}
	case int:
		d.SetInt64(int64(x))
	case int64:
		d.SetInt64(x)
	case uint64:
		d.SetUint64(x)
	case float32:
		d.SetFloat32(x)
	case float64:
		d.SetFloat64(x)
	case string:
		d.SetString(x)
	case []byte:
		d.SetBytes(x)
	case Bit:
		d.SetMysqlBit(x)
	case *MyDecimal:
		d.SetMysqlDecimal(x)
	case Duration:
		d.SetMysqlDuration(x)
	case Enum:
		d.SetMysqlEnum(x)
	case Hex:
		d.SetMysqlHex(x)
	case Set:
		d.SetMysqlSet(x)
	case Time:
		d.SetMysqlTime(x)
	case []Datum:
		d.SetRow(x)
	case []interface{}:
		ds := MakeDatums(x...)
		d.SetRow(ds)
	default:
		d.SetInterface(x)
	}
}
282150
func (config *Config) LogLevel() int {
	if config.ENV.CFLogLevel != "" {
		envVal, err := strconv.ParseInt(config.ENV.CFLogLevel, 10, 32)
		if err == nil {
			return int(envVal)
		}

		switch strings.ToLower(config.ENV.CFLogLevel) {
		case "fatal":
			return 1
		case "error":
			return 2
		case "warn":
			return 3
		case "info":
			return 4
		case "debug":
			return 5
		}
	}

	return 0
}
112537
func (finfo *fieldInfo) value(v reflect.Value) reflect.Value {
	for i, x := range finfo.idx {
		if i > 0 {
			t := v.Type()
			if t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct {
				if v.IsNil() {
					v.Set(reflect.New(v.Type().Elem()))
				}
				v = v.Elem()
			}
		}
		v = v.Field(x)
	}
	return v
}
692785
func (c C) Modulo(val Input) Input {
	if v, ok := val.(C); ok {
		return C(float32(int(c) % int(v)))
	}
	return c
}
47648
func (modulators ModulatorArray) Modulate(msg *Message) ModulateResult {
	action := ModulateResultContinue
	for _, modulator := range modulators {
		switch modRes := modulator.Modulate(msg); modRes {
		case ModulateResultDiscard, ModulateResultFallback:
			return modRes // ### return, break modulator calls ###
		}
	}
	return action
}
283051
func (l *logger) SetField(name string, value interface{}) {
	if l.fields == nil {
		l.fields = map[string]interface{}{}
	}
	l.fields[name] = value
}
889028
func (v *VerbalExpression) addmodifier(f Flag) *VerbalExpression {
	v.compiled = false //reinit previous regexp compilation
	v.flags |= f
	return v
}
425405
func (p *parseContext) Apply() error {
	for _, apply := range p.apply {
		if err := setField(apply.pos, apply.strct, apply.field, apply.fieldValue); err != nil {
			return err
		}
	}
	p.apply = nil
	return nil
}