예제 #1
1
		floatBuiltin1(func(x float64) (Datum, error) {
			return DFloat(math.Log10(x)), nil
		}),
		decimalLogFn(decimal.Log10),
	},

	"mod": {
		floatBuiltin2(func(x, y float64) (Datum, error) {
			return DFloat(math.Mod(x, y)), nil
		}),
		decimalBuiltin2(func(x, y *inf.Dec) (Datum, error) {
			if y.Sign() == 0 {
				return nil, errZeroModulus
			}
			dd := &DDecimal{}
			decimal.Mod(&dd.Dec, x, y)
			return dd, nil
		}),
		builtin{
			returnType: typeInt,
			types:      argTypes{intType, intType},
			fn: func(_ EvalContext, args DTuple) (Datum, error) {
				y := args[1].(DInt)
				if y == 0 {
					return DNull, errZeroModulus
				}
				x := args[0].(DInt)
				return DInt(x % y), nil
			},
		},
	},
예제 #2
0
	binArgs{Mod, floatType, floatType}: {
		returnType: DummyFloat,
		fn: func(_ EvalContext, left Datum, right Datum) (Datum, error) {
			return DFloat(math.Mod(float64(left.(DFloat)), float64(right.(DFloat)))), nil
		},
	},
	binArgs{Mod, decimalType, decimalType}: {
		returnType: DummyDecimal,
		fn: func(_ EvalContext, left Datum, right Datum) (Datum, error) {
			l := left.(*DDecimal).Dec
			r := right.(*DDecimal).Dec
			if r.Sign() == 0 {
				return nil, errZeroModulus
			}
			dd := &DDecimal{}
			decimal.Mod(&dd.Dec, &l, &r)
			return dd, nil
		},
	},

	binArgs{Concat, stringType, stringType}: {
		returnType: DummyString,
		fn: func(_ EvalContext, left Datum, right Datum) (Datum, error) {
			return left.(DString) + right.(DString), nil
		},
	},
	binArgs{Concat, bytesType, bytesType}: {
		returnType: DummyBytes,
		fn: func(_ EvalContext, left Datum, right Datum) (Datum, error) {
			return left.(DBytes) + right.(DBytes), nil
		},