// DecimalNeg reverses decimal's sign.
163707
func DecimalNeg(from *MyDecimal) *MyDecimal {
	to := *from
	if from.IsZero() {
		return &to
	}
	to.negative = !from.negative
	return &to
}
1300168
func (u *Unit) NewValue(value int64, explicitSign Sign) (*Value, error) {
	if (value < 0 && explicitSign == Positive) || (value > 0 && explicitSign == Negative) {
		return nil, errors.New("Invalid value/explicitSign combination")
	}

	return &Value{
		unit:         u,
		Value:        value,
		ExplicitSign: explicitSign,
	}, nil
}
619432
func (a *decimal) Shift(k int) {
	switch {
	case a.nd == 0:
		// nothing to do: a == 0
	case k > 0:
		for k > maxShift {
			leftShift(a, maxShift)
			k -= maxShift
		}
		leftShift(a, uint(k))
	case k < 0:
		for k < -maxShift {
			rightShift(a, maxShift)
			k += maxShift
		}
		rightShift(a, uint(-k))
	}
}
991605
func DecodeBig(input string) (*big.Int, error) {
	raw, err := checkNumber(input)
	if err != nil {
		return nil, err
	}
	if len(raw) > 64 {
		return nil, ErrBig256Range
	}
	words := make([]big.Word, len(raw)/bigWordNibbles+1)
	end := len(raw)
	for i := range words {
		start := end - bigWordNibbles
		if start < 0 {
			start = 0
		}
		for ri := start; ri < end; ri++ {
			nib := decodeNibble(raw[ri])
			if nib == badNibble {
				return nil, ErrSyntax
			}
			words[i] *= 16
			words[i] += big.Word(nib)
		}
		end = start
	}
	dec := new(big.Int).SetBits(words)
	return dec, nil
}
398780
func FilterNeg(f func(ma.Multiaddr) bool) func(ma.Multiaddr) bool {
	return func(a ma.Multiaddr) bool {
		return !f(a)
	}
}
276330
func itod(i uint) string {
	if i == 0 {
		return "0"
	}

	// Assemble decimal in reverse order.
	var b [32]byte
	bp := len(b)
	for ; i > 0; i /= 10 {
		bp--
		b[bp] = byte(i%10) + '0'
	}

	return string(b[bp:])
}
1133277
func decimalBinSize(precision, frac int) int {
	digitsInt := precision - frac
	wordsInt := digitsInt / digitsPerWord
	wordsFrac := frac / digitsPerWord
	xInt := digitsInt - wordsInt*digitsPerWord
	xFrac := frac - wordsFrac*digitsPerWord
	return wordsInt*wordSize + dig2bytes[xInt] + wordsFrac*wordSize + dig2bytes[xFrac]
}
660178
func (a *decimal) Assign(v uint64) {
	var buf [24]byte

	// Write reversed decimal in buf.
	n := 0
	for v > 0 {
		v1 := v / 10
		v -= 10 * v1
		buf[n] = byte(v + '0')
		n++
		v = v1
	}

	// Reverse again to produce forward decimal in a.d.
	a.nd = 0
	for n--; n >= 0; n-- {
		a.d[a.nd] = buf[n]
		a.nd++
	}
	a.dp = a.nd
	trim(a)
}
495898
func Decimal(num []byte, prec int) []byte {
	// omit first + and register mantissa start and end, whether it's negative and the exponent
	neg := false
	start := 0
	dot := -1
	end := len(num)
	if 0 < end && (num[0] == '+' || num[0] == '-') {
		if num[0] == '-' {
			neg = true
		}
		start++
	}
	for i, c := range num[start:] {
		if c == '.' {
			dot = start + i
			break
		}
	}
	if dot == -1 {
		dot = end
	}

	// trim leading zeros but leave at least one digit
	for start < end-1 && num[start] == '0' {
		start++
	}
	// trim trailing zeros
	i := end - 1
	for ; i > dot; i-- {
		if num[i] != '0' {
			end = i + 1
			break
		}
	}
	if i == dot {
		end = dot
		if start == end {
			num[start] = '0'
			return num[start : start+1]
		}
	} else if start == end-1 && num[start] == '0' {
		return num[start:end]
	}

	// apply precision
	if prec > -1 && dot+1+prec < end {
		end = dot + 1 + prec
		inc := num[end] >= '5'
		if inc || num[end-1] == '0' {
			// process either an increase from a lesser significant decimal (>= 5)
			// or remove trailing zeros after the dot, or both
			for i := end - 1; i > start; i-- {
				if i == dot {
					end--
				} else if inc {
					if num[i] == '9' {
						if i > dot {
							end--
						} else {
							num[i] = '0'
							break
						}
					} else {
						num[i]++
						inc = false
						break
					}
				} else if i > dot && num[i] == '0' {
					end--
				} else {
					break
				}
			}
		}
		if dot == start && end == start+1 {
			if inc {
				num[start] = '1'
			} else {
				num[start] = '0'
			}
		} else {
			if dot+1 == end {
				end--
			}
			if inc {
				if num[start] == '9' {
					num[start] = '0'
					copy(num[start+1:], num[start:end])
					end++
					num[start] = '1'
				} else {
					num[start]++
				}
			}
		}
	}

	if neg {
		start--
		num[start] = '-'
	}
	return num[start:end]
}
488217
func Unsign(v string, s string) string {
	i := strings.LastIndex(v, ".")
	if i == -1 {
		return ""
	}
	val := v[:i]
	if Sign(val, s) != v {
		return ""
	}
	return val
}
259857
func TruncateFloat(f float64, flen int, decimal int) (float64, error) {
	if math.IsNaN(f) {
		// nan returns 0
		return 0, ErrOverflow.GenWithStackByArgs("DOUBLE", "")
	}

	maxF := GetMaxFloat(flen, decimal)

	if !math.IsInf(f, 0) {
		f = Round(f, decimal)
	}

	var err error
	if f > maxF {
		f = maxF
		err = ErrOverflow.GenWithStackByArgs("DOUBLE", "")
	} else if f < -maxF {
		f = -maxF
		err = ErrOverflow.GenWithStackByArgs("DOUBLE", "")
	}

	return f, errors.Trace(err)
}
758431
func NewRegExpWithFlag(s string, flags int) *RegExp {
	ans := &RegExp{
		b:     []rune(s),
		flags: flags,
	}
	var e *RegExp
	if len(s) == 0 {
		e = makeStringRE("")
	} else {
		e = ans.parseUnionExp()
		if ans.pos < len(ans.b) {
			panic(fmt.Sprintf("end-of-string expected at position %v", ans.pos))
		}
	}
	ans.kind = e.kind
	ans.exp1, ans.exp2 = e.exp1, e.exp2
	ans.s = e.s
	ans.c = e.c
	ans.min, ans.max, ans.digits = e.min, e.max, e.digits
	ans.from, ans.to = e.from, e.to
	ans.b = nil
	return ans
}
1243102
func (v *Value) negate() {
	switch v.vType {
	case typeFloat:
		v.value = -(v.value.(float64))
	case typeInt:
		v.value = -(v.value.(int64))
	}
}
1029688
func ITOD(i uint) string {
	if i == 0 {
		return "0"
	}

	// Assemble decimal in reverse order.
	var b [32]byte
	bp := len(b)
	for ; i > 0; i /= 10 {
		bp--
		b[bp] = byte(i%10) + '0'
	}

	return string(b[bp:])
}
153263
func (b *builtinReverseSig) evalString(row chunk.Row) (string, bool, error) {
	str, isNull, err := b.args[0].EvalString(b.ctx, row)
	if isNull || err != nil {
		return "", true, err
	}
	reversed := reverseRunes([]rune(str))
	return string(reversed), false, nil
}
49903
func (e *GT) Neg(a *GT) *GT {
	if e.p == nil {
		e.p = &gfP12{}
	}
	e.p.Conjugate(a.p)
	return e
}
954906
func (p *parser) negation(t *Token) (Pattern, Error) {
	// a negation appears before a path specification, so
	// skip the negation token
	_next, _err := p.next()
	if _err != nil {
		return nil, _err
	}

	// extract the sequence of tokens for this path
	_tokens, _err := p.sequence(_next)
	if _err != nil {
		return nil, _err
	}

	// include the "negation" token at the front of the sequence
	_tokens = append([]*Token{t}, _tokens...)

	// return the Pattern instance
	return NewPattern(_tokens), nil
}