pkg/math: added MultipleOf

Also:
- add support for Decimal type (internal)
- add correspondng support in openapi package

Change-Id: Idc4b829423bba63380a8edfc1109c345f4248355
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2640
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/pkg/math/manual.go b/pkg/math/manual.go
index 493f8c5..361a6c1 100644
--- a/pkg/math/manual.go
+++ b/pkg/math/manual.go
@@ -14,7 +14,12 @@
 
 package math
 
-import "math"
+import (
+	"math"
+
+	"cuelang.org/go/internal"
+	"github.com/cockroachdb/apd/v2"
+)
 
 // TODO: use apd
 
@@ -67,3 +72,12 @@
 func RoundToEven(x float64) float64 {
 	return math.RoundToEven(x)
 }
+
+var mulContext = apd.BaseContext.WithPrecision(1)
+
+// MultipleOf reports whether x is a multiple of y.
+func MultipleOf(x, y *internal.Decimal) (bool, error) {
+	var d apd.Decimal
+	cond, err := mulContext.Quo(&d, x, y)
+	return !cond.Inexact(), err
+}