Repository: goplus/gop
Pull request #1154 (2022-04-22 09:59:37)

builtin/big => builtin/ng


Patch:
diff --git a/builtin/big/big.go b/builtin/big/big.go
deleted file mode 100644
index e7d04f04..00000000
--- a/builtin/big/big.go
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- * Copyright (c) 2021 The GoPlus Authors (goplus.org). All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package big
-
-import (
-	"math/big"
-)
-
-const (
-	GopPackage = true // to indicate this is a Go+ package
-)
-
-//
-// Gop_: Go+ object prefix
-// Gop_xxx_Cast: type Gop_xxx typecast
-// xxxx__N: the Nth overload function
-//
-
-type Gop_ninteger = uint
-
-func Gop_istmp(a interface{}) bool {
-	return false
-}
-
-// -----------------------------------------------------------------------------
-
-type UntypedInt *big.Int
-type UntypedRat *big.Rat
-type UntypedFloat *big.Float
-
-type UntypedInt_Default = Int
-type UntypedRat_Default = Rat
-type UntypedFloat_Default = Float
-
-func UntypedInt_Init__0(x int) UntypedInt {
-	panic(makeCompilerHappy)
-}
-
-func UntypedRat_Init__0(x int) UntypedRat {
-	panic(makeCompilerHappy)
-}
-
-func UntypedRat_Init__1(x UntypedInt) UntypedRat {
-	panic(makeCompilerHappy)
-}
-
-const (
-	makeCompilerHappy = "make compiler happy"
-)
-
-// -----------------------------------------------------------------------------
-// type bigint
-
-// A Int represents a signed multi-precision integer.
-// The zero value for a Int represents nil.
-type Int struct {
-	*big.Int
-}
-
-func tmpint(a, b Int) Int {
-	if Gop_istmp(a) {
-		return a
-	} else if Gop_istmp(b) {
-		return b
-	}
-	return Int{new(big.Int)}
-}
-
-func tmpint1(a Int) Int {
-	if Gop_istmp(a) {
-		return a
-	}
-	return Int{new(big.Int)}
-}
-
-// IsNil returns a bigint object is nil or not
-func (a Int) IsNil() bool {
-	return a.Int == nil
-}
-
-// Gop_Assign: func (a bigint) = (b bigint)
-func (a Int) Gop_Assign(b Int) {
-	if Gop_istmp(b) {
-		*a.Int = *b.Int
-	} else {
-		a.Int.Set(b.Int)
-	}
-}
-
-// Gop_Add: func (a bigint) + (b bigint) bigint
-func (a Int) Gop_Add(b Int) Int {
-	return Int{tmpint(a, b).Add(a.Int, b.Int)}
-}
-
-// Gop_Sub: func (a bigint) - (b bigint) bigint
-func (a Int) Gop_Sub(b Int) Int {
-	return Int{tmpint(a, b).Sub(a.Int, b.Int)}
-}
-
-// Gop_Mul: func (a bigint) * (b bigint) bigint
-func (a Int) Gop_Mul(b Int) Int {
-	return Int{tmpint(a, b).Mul(a.Int, b.Int)}
-}
-
-// Gop_Quo: func (a bigint) / (b bigint) bigint {
-func (a Int) Gop_Quo(b Int) Int {
-	return Int{tmpint(a, b).Quo(a.Int, b.Int)}
-}
-
-// Gop_Rem: func (a bigint) % (b bigint) bigint
-func (a Int) Gop_Rem(b Int) Int {
-	return Int{tmpint(a, b).Rem(a.Int, b.Int)}
-}
-
-// Gop_Or: func (a bigint) | (b bigint) bigint
-func (a Int) Gop_Or(b Int) Int {
-	return Int{tmpint(a, b).Or(a.Int, b.Int)}
-}
-
-// Gop_Xor: func (a bigint) ^ (b bigint) bigint
-func (a Int) Gop_Xor(b Int) Int {
-	return Int{tmpint(a, b).Xor(a.Int, b.Int)}
-}
-
-// Gop_And: func (a bigint) & (b bigint) bigint
-func (a Int) Gop_And(b Int) Int {
-	return Int{tmpint(a, b).And(a.Int, b.Int)}
-}
-
-// Gop_AndNot: func (a bigint) &^ (b bigint) bigint
-func (a Int) Gop_AndNot(b Int) Int {
-	return Int{tmpint(a, b).AndNot(a.Int, b.Int)}
-}
-
-// Gop_Lsh: func (a bigint) << (n untyped_uint) bigint
-func (a Int) Gop_Lsh(n Gop_ninteger) Int {
-	return Int{tmpint1(a).Lsh(a.Int, uint(n))}
-}
-
-// Gop_Rsh: func (a bigint) >> (n untyped_uint) bigint
-func (a Int) Gop_Rsh(n Gop_ninteger) Int {
-	return Int{tmpint1(a).Rsh(a.Int, uint(n))}
-}
-
-// Gop_LT: func (a bigint) < (b bigint) bool
-func (a Int) Gop_LT(b Int) bool {
-	return a.Cmp(b.Int) < 0
-}
-
-// Gop_LE: func (a bigint) <= (b bigint) bool
-func (a Int) Gop_LE(b Int) bool {
-	return a.Cmp(b.Int) <= 0
-}
-
-// Gop_GT: func (a bigint) > (b bigint) bool
-func (a Int) Gop_GT(b Int) bool {
-	return a.Cmp(b.Int) > 0
-}
-
-// Gop_GE: func (a bigint) >= (b bigint) bool
-func (a Int) Gop_GE(b Int) bool {
-	return a.Cmp(b.Int) >= 0
-}
-
-// Gop_EQ: func (a bigint) == (b bigint) bool
-func (a Int) Gop_EQ(b Int) bool {
-	return a.Cmp(b.Int) == 0
-}
-
-// Gop_NE: func (a bigint) != (b bigint) bool
-func (a Int) Gop_NE(b Int) bool {
-	return a.Cmp(b.Int) != 0
-}
-
-// Gop_Neg: func -(a bigint) bigint
-func (a Int) Gop_Neg() Int {
-	return Int{tmpint1(a).Neg(a.Int)}
-}
-
-// Gop_Pos: func +(a bigint) bigint
-func (a Int) Gop_Pos() Int {
-	return a
-}
-
-// Gop_Not: func ^(a bigint) bigint
-func (a Int) Gop_Not() Int {
-	return Int{tmpint1(a).Not(a.Int)}
-}
-
-// Gop_Add: func (a bigint) += (b bigint)
-func (a Int) Gop_AddAssign(b Int) {
-	a.Int.Add(a.Int, b.Int)
-}
-
-// Gop_Sub: func (a bigint) -= (b bigint)
-func (a Int) Gop_SubAssign(b Int) {
-	a.Int.Sub(a.Int, b.Int)
-}
-
-// Gop_Mul: func (a bigint) *= (b bigint)
-func (a Int) Gop_MulAssign(b Int) {
-	a.Int.Mul(a.Int, b.Int)
-}
-
-// Gop_Quo: func (a bigint) /= (b bigint) {
-func (a Int) Gop_QuoAssign(b Int) {
-	a.Int.Quo(a.Int, b.Int)
-}
-
-// Gop_Rem: func (a bigint) %= (b bigint)
-func (a Int) Gop_RemAssign(b Int) {
-	a.Int.Rem(a.Int, b.Int)
-}
-
-// Gop_Or: func (a bigint) |= (b bigint)
-func (a Int) Gop_OrAssign(b Int) {
-	a.Int.Or(a.Int, b.Int)
-}
-
-// Gop_Xor: func (a bigint) ^= (b bigint)
-func (a Int) Gop_XorAssign(b Int) {
-	a.Int.Xor(a.Int, b.Int)
-}
-
-// Gop_And: func (a bigint) &= (b bigint)
-func (a Int) Gop_AndAssign(b Int) {
-	a.Int.And(a.Int, b.Int)
-}
-
-// Gop_AndNot: func (a bigint) &^= (b bigint)
-func (a Int) Gop_AndNotAssign(b Int) {
-	a.Int.AndNot(a.Int, b.Int)
-}
-
-// Gop_Lsh: func (a bigint) <<= (n untyped_uint)
-func (a Int) Gop_LshAssign(n Gop_ninteger) {
-	a.Int.Lsh(a.Int, uint(n))
-}
-
-// Gop_Rsh: func (a bigint) >>= (n untyped_uint)
-func (a Int) Gop_RshAssign(n Gop_ninteger) {
-	a.Int.Rsh(a.Int, uint(n))
-}
-
-// Int_Cast: func bigint() bigint
-func Int_Cast__0() Int {
-	return Int{new(big.Int)}
-}
-
-// Int_Cast: func bigint(x int64) bigint
-func Int_Cast__1(x int64) Int {
-	return Int{big.NewInt(x)}
-}
-
-// Int_Cast: func bigint(x int) bigint
-func Int_Cast__2(x int) Int {
-	return Int{big.NewInt(int64(x))}
-}
-
-// Int_Cast: func bigint(x uint64) bigint
-func Int_Cast__3(x uint64) Int {
-	return Int{new(big.Int).SetUint64(x)}
-}
-
-// Int_Cast: func bigint(x uint) bigint
-func Int_Cast__4(x uint) Int {
-	return Int{new(big.Int).SetUint64(uint64(x))}
-}
-
-// Int_Cast: func bigint(x *big.Int) bigint
-func Int_Cast__5(x *big.Int) Int {
-	return Int{x}
-}
-
-// Int_Cast: func bigint(x *big.Rat) bigint
-func Int_Cast__6(x *big.Rat) Int {
-	if x.IsInt() {
-		return Int{x.Num()}
-	}
-	ret, _ := new(big.Float).SetRat(x).Int(nil)
-	return Int{ret}
-}
-
-// Int_Init: func bigint.init(x int) bigint
-func Int_Init__0(x int) Int {
-	return Int{big.NewInt(int64(x))}
-}
-
-// Int_Init: func bigint.init(x *big.Int) bigint
-func Int_Init__1(x *big.Int) Int {
-	return Int{x}
-}
-
-// Int_Init: func bigint.init(x *big.Rat) bigint
-func Int_Init__2(x *big.Rat) Int {
-	if x.IsInt() {
-		return Int{x.Num()}
-	}
-	panic("TODO: can't init bigint from bigrat")
-}
-
-// -----------------------------------------------------------------------------
-// type bigrat
-
-// A Rat represents a quotient a/b of arbitrary precision.
-// The zero value for a Rat represents nil.
-type Rat struct {
-	*big.Rat
-}
-
-func tmprat(a, b Rat) Rat {
-	if Gop_istmp(a) {
-		return a
-	} else if Gop_istmp(b) {
-		return b
-	}
-	return Rat{new(big.Rat)}
-}
-
-func tmprat1(a Rat) Rat {
-	if Gop_istmp(a) {
-		return a
-	}
-	return Rat{new(big.Rat)}
-}
-
-// IsNil returns a bigrat object is nil or not
-func (a Rat) IsNil() bool {
-	return a.Rat == nil
-}
-
-// Gop_Assign: func (a bigrat) = (b bigrat)
-func (a Rat) Gop_Assign(b Rat) {
-	if Gop_istmp(b) {
-		*a.Rat = *b.Rat
-	} else {
-		a.Rat.Set(b.Rat)
-	}
-}
-
-// Gop_Add: func (a bigrat) + (b bigrat) bigrat
-func (a Rat) Gop_Add(b Rat) Rat {
-	return Rat{tmprat(a, b).Add(a.Rat, b.Rat)}
-}
-
-// Gop_Sub: func (a bigrat) - (b bigrat) bigrat
-func (a Rat) Gop_Sub(b Rat) Rat {
-	return Rat{tmprat(a, b).Sub(a.Rat, b.Rat)}
-}
-
-// Gop_Mul: func (a bigrat) * (b bigrat) bigrat
-func (a Rat) Gop_Mul(b Rat) Rat {
-	return Rat{tmprat(a, b).Mul(a.Rat, b.Rat)}
-}
-
-// Gop_Quo: func (a bigrat) / (b bigrat) bigrat
-func (a Rat) Gop_Quo(b Rat) Rat {
-	return Rat{tmprat(a, b).Quo(a.Rat, b.Rat)}
-}
-
-// Gop_LT: func (a bigrat) < (b bigrat) bool
-func (a Rat) Gop_LT(b Rat) bool {
-	return a.Cmp(b.Rat) < 0
-}
-
-// Gop_LE: func (a bigrat) <= (b bigrat) bool
-func (a Rat) Gop_LE(b Rat) bool {
-	return a.Cmp(b.Rat) <= 0
-}
-
-// Gop_GT: func (a bigrat) > (b bigrat) bool
-func (a Rat) Gop_GT(b Rat) bool {
-	return a.Cmp(b.Rat) > 0
-}
-
-// Gop_GE: func (a bigrat) >= (b bigrat) bool
-func (a Rat) Gop_GE(b Rat) bool {
-	return a.Cmp(b.Rat) >= 0
-}
-
-// Gop_EQ: func (a bigrat) == (b bigrat) bool
-func (a Rat) Gop_EQ(b Rat) bool {
-	return a.Cmp(b.Rat) == 0
-}
-
-// Gop_NE: func (a bigrat) != (b bigrat) bool
-func (a Rat) Gop_NE(b Rat) bool {
-	return a.Cmp(b.Rat) != 0
-}
-
-// Gop_Neg: func -(a bigrat) bigrat
-func (a Rat) Gop_Neg() Rat {
-	return Rat{tmprat1(a).Neg(a.Rat)}
-}
-
-// Gop_Pos: func +(a bigrat) bigrat
-func (a Rat) Gop_Pos() Rat {
-	return a
-}
-
-// Gop_Inv: func /(a bigrat) bigrat
-func (a Rat) Gop_Inv() Rat {
-	return Rat{tmprat1(a).Inv(a.Rat)}
-}
-
-// Gop_Add: func (a bigrat) += (b bigrat)
-func (a Rat) Gop_AddAssign(b Rat) {
-	a.Rat.Add(a.Rat, b.Rat)
-}
-
-// Gop_Sub: func (a bigrat) -= (b bigrat)
-func (a Rat) Gop_SubAssign(b Rat) {
-	a.Rat.Sub(a.Rat, b.Rat)
-}
-
-// Gop_Mul: func (a bigrat) *= (b bigrat)
-func (a Rat) Gop_MulAssign(b Rat) {
-	a.Rat.Mul(a.Rat, b.Rat)
-}
-
-// Gop_Quo: func (a bigrat) /= (b bigrat)
-func (a Rat) Gop_QuoAssign(b Rat) {
-	a.Rat.Quo(a.Rat, b.Rat)
-}
-
-// Rat_Cast: func bigrat() bigrat
-func Rat_Cast__0() Rat {
-	return Rat{new(big.Rat)}
-}
-
-// Rat_Cast: func bigrat(a bigint) bigrat
-func Rat_Cast__1(a Int) Rat {
-	return Rat{new(big.Rat).SetInt(a.Int)}
-}
-
-// Rat_Cast: func bigrat(a *big.Int) bigrat
-func Rat_Cast__2(a *big.Int) Rat {
-	return Rat{new(big.Rat).SetInt(a)}
-}
-
-// Rat_Cast: func bigrat(a, b int64) bigrat
-func Rat_Cast__3(a, b int64) Rat {
-	return Rat{big.NewRat(a, b)}
-}
-
-// Rat_Cast: func bigrat(a *big.Rat) bigrat
-func Rat_Cast__4(a *big.Rat) Rat {
-	return Rat{a}
-}
-
-// Rat_Init: func bigrat.init(x untyped_int) bigrat
-func Rat_Init__0(x int) Rat {
-	return Rat{big.NewRat(int64(x), 1)}
-}
-
-// Rat_Init: func bigrat.init(x untyped_bigint) bigrat
-func Rat_Init__1(x UntypedInt) Rat {
-	return Rat{new(big.Rat).SetInt(x)}
-}
-
-// Rat_Init: func bigrat.init(x *big.Rat) bigrat
-func Rat_Init__2(x *big.Rat) Rat {
-	return Rat{x}
-}
-
-// -----------------------------------------------------------------------------
-// type bigfloat
-
-// A Float represents a multi-precision floating point number.
-// The zero value for a Float represents nil.
-type Float struct {
-	*big.Float
-}
-
-// -----------------------------------------------------------------------------
diff --git a/builtin/big/_big.gop b/builtin/ng/_big.gop
similarity index 100%
rename from builtin/big/_big.gop
rename to builtin/ng/_big.gop
diff --git a/builtin/ng/big.go b/builtin/ng/big.go
new file mode 100644
index 00000000..9f755eaf
--- /dev/null
+++ b/builtin/ng/big.go
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2021 The GoPlus Authors (goplus.org). All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ng
+
+import (
+	"math/big"
+)
+
+func Gop_istmp(a interface{}) bool {
+	return false
+}
+
+// -----------------------------------------------------------------------------
+
+type UntypedBigint *big.Int
+type UntypedBigrat *big.Rat
+type UntypedBigfloat *big.Float
+
+type UntypedBigint_Default = Bigint
+type UntypedBigrat_Default = Bigrat
+type UntypedBigfloat_Default = Bigfloat
+
+func UntypedBigint_Init__0(x int) UntypedBigint {
+	panic(makeCompilerHappy)
+}
+
+func UntypedBigrat_Init__0(x int) UntypedBigrat {
+	panic(makeCompilerHappy)
+}
+
+func UntypedBigrat_Init__1(x UntypedBigint) UntypedBigrat {
+	panic(makeCompilerHappy)
+}
+
+const (
+	makeCompilerHappy = "make compiler happy"
+)
+
+// -----------------------------------------------------------------------------
+// type bigint
+
+// A Bigint represents a signed multi-precision integer.
+// The zero value for a Bigint represents nil.
+type Bigint struct {
+	*big.Int
+}
+
+func tmpint(a, b Bigint) Bigint {
+	if Gop_istmp(a) {
+		return a
+	} else if Gop_istmp(b) {
+		return b
+	}
+	return Bigint{new(big.Int)}
+}
+
+func tmpint1(a Bigint) Bigint {
+	if Gop_istmp(a) {
+		return a
+	}
+	return Bigint{new(big.Int)}
+}
+
+// IsNil returns a bigint object is nil or not
+func (a Bigint) IsNil() bool {
+	return a.Int == nil
+}
+
+// Gop_Assign: func (a bigint) = (b bigint)
+func (a Bigint) Gop_Assign(b Bigint) {
+	if Gop_istmp(b) {
+		*a.Int = *b.Int
+	} else {
+		a.Int.Set(b.Int)
+	}
+}
+
+// Gop_Add: func (a bigint) + (b bigint) bigint
+func (a Bigint) Gop_Add(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Add(a.Int, b.Int)}
+}
+
+// Gop_Sub: func (a bigint) - (b bigint) bigint
+func (a Bigint) Gop_Sub(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Sub(a.Int, b.Int)}
+}
+
+// Gop_Mul: func (a bigint) * (b bigint) bigint
+func (a Bigint) Gop_Mul(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Mul(a.Int, b.Int)}
+}
+
+// Gop_Quo: func (a bigint) / (b bigint) bigint {
+func (a Bigint) Gop_Quo(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Quo(a.Int, b.Int)}
+}
+
+// Gop_Rem: func (a bigint) % (b bigint) bigint
+func (a Bigint) Gop_Rem(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Rem(a.Int, b.Int)}
+}
+
+// Gop_Or: func (a bigint) | (b bigint) bigint
+func (a Bigint) Gop_Or(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Or(a.Int, b.Int)}
+}
+
+// Gop_Xor: func (a bigint) ^ (b bigint) bigint
+func (a Bigint) Gop_Xor(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).Xor(a.Int, b.Int)}
+}
+
+// Gop_And: func (a bigint) & (b bigint) bigint
+func (a Bigint) Gop_And(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).And(a.Int, b.Int)}
+}
+
+// Gop_AndNot: func (a bigint) &^ (b bigint) bigint
+func (a Bigint) Gop_AndNot(b Bigint) Bigint {
+	return Bigint{tmpint(a, b).AndNot(a.Int, b.Int)}
+}
+
+// Gop_Lsh: func (a bigint) << (n untyped_uint) bigint
+func (a Bigint) Gop_Lsh(n Gop_ninteger) Bigint {
+	return Bigint{tmpint1(a).Lsh(a.Int, uint(n))}
+}
+
+// Gop_Rsh: func (a bigint) >> (n untyped_uint) bigint
+func (a Bigint) Gop_Rsh(n Gop_ninteger) Bigint {
+	return Bigint{tmpint1(a).Rsh(a.Int, uint(n))}
+}
+
+// Gop_LT: func (a bigint) < (b bigint) bool
+func (a Bigint) Gop_LT(b Bigint) bool {
+	return a.Cmp(b.Int) < 0
+}
+
+// Gop_LE: func (a bigint) <= (b bigint) bool
+func (a Bigint) Gop_LE(b Bigint) bool {
+	return a.Cmp(b.Int) <= 0
+}
+
+// Gop_GT: func (a bigint) > (b bigint) bool
+func (a Bigint) Gop_GT(b Bigint) bool {
+	return a.Cmp(b.Int) > 0
+}
+
+// Gop_GE: func (a bigint) >= (b bigint) bool
+func (a Bigint) Gop_GE(b Bigint) bool {
+	return a.Cmp(b.Int) >= 0
+}
+
+// Gop_EQ: func (a bigint) == (b bigint) bool
+func (a Bigint) Gop_EQ(b Bigint) bool {
+	return a.Cmp(b.Int) == 0
+}
+
+// Gop_NE: func (a bigint) != (b bigint) bool
+func (a Bigint) Gop_NE(b Bigint) bool {
+	return a.Cmp(b.Int) != 0
+}
+
+// Gop_Neg: func -(a bigint) bigint
+func (a Bigint) Gop_Neg() Bigint {
+	return Bigint{tmpint1(a).Neg(a.Int)}
+}
+
+// Gop_Pos: func +(a bigint) bigint
+func (a Bigint) Gop_Pos() Bigint {
+	return a
+}
+
+// Gop_Not: func ^(a bigint) bigint
+func (a Bigint) Gop_Not() Bigint {
+	return Bigint{tmpint1(a).Not(a.Int)}
+}
+
+// Gop_Add: func (a bigint) += (b bigint)
+func (a Bigint) Gop_AddAssign(b Bigint) {
+	a.Int.Add(a.Int, b.Int)
+}
+
+// Gop_Sub: func (a bigint) -= (b bigint)
+func (a Bigint) Gop_SubAssign(b Bigint) {
+	a.Int.Sub(a.Int, b.Int)
+}
+
+// Gop_Mul: func (a bigint) *= (b bigint)
+func (a Bigint) Gop_MulAssign(b Bigint) {
+	a.Int.Mul(a.Int, b.Int)
+}
+
+// Gop_Quo: func (a bigint) /= (b bigint) {
+func (a Bigint) Gop_QuoAssign(b Bigint) {
+	a.Int.Quo(a.Int, b.Int)
+}
+
+// Gop_Rem: func (a bigint) %= (b bigint)
+func (a Bigint) Gop_RemAssign(b Bigint) {
+	a.Int.Rem(a.Int, b.Int)
+}
+
+// Gop_Or: func (a bigint) |= (b bigint)
+func (a Bigint) Gop_OrAssign(b Bigint) {
+	a.Int.Or(a.Int, b.Int)
+}
+
+// Gop_Xor: func (a bigint) ^= (b bigint)
+func (a Bigint) Gop_XorAssign(b Bigint) {
+	a.Int.Xor(a.Int, b.Int)
+}
+
+// Gop_And: func (a bigint) &= (b bigint)
+func (a Bigint) Gop_AndAssign(b Bigint) {
+	a.Int.And(a.Int, b.Int)
+}
+
+// Gop_AndNot: func (a bigint) &^= (b bigint)
+func (a Bigint) Gop_AndNotAssign(b Bigint) {
+	a.Int.AndNot(a.Int, b.Int)
+}
+
+// Gop_Lsh: func (a bigint) <<= (n untyped_uint)
+func (a Bigint) Gop_LshAssign(n Gop_ninteger) {
+	a.Int.Lsh(a.Int, uint(n))
+}
+
+// Gop_Rsh: func (a bigint) >>= (n untyped_uint)
+func (a Bigint) Gop_RshAssign(n Gop_ninteger) {
+	a.Int.Rsh(a.Int, uint(n))
+}
+
+// Bigint_Cast: func bigint() bigint
+func Bigint_Cast__0() Bigint {
+	return Bigint{new(big.Int)}
+}
+
+// Bigint_Cast: func bigint(x int64) bigint
+func Bigint_Cast__1(x int64) Bigint {
+	return Bigint{big.NewInt(x)}
+}
+
+// Bigint_Cast: func bigint(x int) bigint
+func Bigint_Cast__2(x int) Bigint {
+	return Bigint{big.NewInt(int64(x))}
+}
+
+// Bigint_Cast: func bigint(x uint64) bigint
+func Bigint_Cast__3(x uint64) Bigint {
+	return Bigint{new(big.Int).SetUint64(x)}
+}
+
+// Bigint_Cast: func bigint(x uint) bigint
+func Bigint_Cast__4(x uint) Bigint {
+	return Bigint{new(big.Int).SetUint64(uint64(x))}
+}
+
+// Bigint_Cast: func bigint(x *big.Int) bigint
+func Bigint_Cast__5(x *big.Int) Bigint {
+	return Bigint{x}
+}
+
+// Bigint_Cast: func bigint(x *big.Rat) bigint
+func Bigint_Cast__6(x *big.Rat) Bigint {
+	if x.IsInt() {
+		return Bigint{x.Num()}
+	}
+	ret, _ := new(big.Float).SetRat(x).Int(nil)
+	return Bigint{ret}
+}
+
+// Bigint_Init: func bigint.init(x int) bigint
+func Bigint_Init__0(x int) Bigint {
+	return Bigint{big.NewInt(int64(x))}
+}
+
+// Bigint_Init: func bigint.init(x *big.Int) bigint
+func Bigint_Init__1(x *big.Int) Bigint {
+	return Bigint{x}
+}
+
+// Bigint_Init: func bigint.init(x *big.Rat) bigint
+func Bigint_Init__2(x *big.Rat) Bigint {
+	if x.IsInt() {
+		return Bigint{x.Num()}
+	}
+	panic("TODO: can't init bigint from bigrat")
+}
+
+// -----------------------------------------------------------------------------
+// type bigrat
+
+// A Bigrat represents a quotient a/b of arbitrary precision.
+// The zero value for a Bigrat represents nil.
+type Bigrat struct {
+	*big.Rat
+}
+
+func tmprat(a, b Bigrat) Bigrat {
+	if Gop_istmp(a) {
+		return a
+	} else if Gop_istmp(b) {
+		return b
+	}
+	return Bigrat{new(big.Rat)}
+}
+
+func tmprat1(a Bigrat) Bigrat {
+	if Gop_istmp(a) {
+		return a
+	}
+	return Bigrat{new(big.Rat)}
+}
+
+// IsNil returns a bigrat object is nil or not
+func (a Bigrat) IsNil() bool {
+	return a.Rat == nil
+}
+
+// Gop_Assign: func (a bigrat) = (b bigrat)
+func (a Bigrat) Gop_Assign(b Bigrat) {
+	if Gop_istmp(b) {
+		*a.Rat = *b.Rat
+	} else {
+		a.Rat.Set(b.Rat)
+	}
+}
+
+// Gop_Add: func (a bigrat) + (b bigrat) bigrat
+func (a Bigrat) Gop_Add(b Bigrat) Bigrat {
+	return Bigrat{tmprat(a, b).Add(a.Rat, b.Rat)}
+}
+
+// Gop_Sub: func (a bigrat) - (b bigrat) bigrat
+func (a Bigrat) Gop_Sub(b Bigrat) Bigrat {
+	return Bigrat{tmprat(a, b).Sub(a.Rat, b.Rat)}
+}
+
+// Gop_Mul: func (a bigrat) * (b bigrat) bigrat
+func (a Bigrat) Gop_Mul(b Bigrat) Bigrat {
+	return Bigrat{tmprat(a, b).Mul(a.Rat, b.Rat)}
+}
+
+// Gop_Quo: func (a bigrat) / (b bigrat) bigrat
+func (a Bigrat) Gop_Quo(b Bigrat) Bigrat {
+	return Bigrat{tmprat(a, b).Quo(a.Rat, b.Rat)}
+}
+
+// Gop_LT: func (a bigrat) < (b bigrat) bool
+func (a Bigrat) Gop_LT(b Bigrat) bool {
+	return a.Cmp(b.Rat) < 0
+}
+
+// Gop_LE: func (a bigrat) <= (b bigrat) bool
+func (a Bigrat) Gop_LE(b Bigrat) bool {
+	return a.Cmp(b.Rat) <= 0
+}
+
+// Gop_GT: func (a bigrat) > (b bigrat) bool
+func (a Bigrat) Gop_GT(b Bigrat) bool {
+	return a.Cmp(b.Rat) > 0
+}
+
+// Gop_GE: func (a bigrat) >= (b bigrat) bool
+func (a Bigrat) Gop_GE(b Bigrat) bool {
+	return a.Cmp(b.Rat) >= 0
+}
+
+// Gop_EQ: func (a bigrat) == (b bigrat) bool
+func (a Bigrat) Gop_EQ(b Bigrat) bool {
+	return a.Cmp(b.Rat) == 0
+}
+
+// Gop_NE: func (a bigrat) != (b bigrat) bool
+func (a Bigrat) Gop_NE(b Bigrat) bool {
+	return a.Cmp(b.Rat) != 0
+}
+
+// Gop_Neg: func -(a bigrat) bigrat
+func (a Bigrat) Gop_Neg() Bigrat {
+	return Bigrat{tmprat1(a).Neg(a.Rat)}
+}
+
+// Gop_Pos: func +(a bigrat) bigrat
+func (a Bigrat) Gop_Pos() Bigrat {
+	return a
+}
+
+// Gop_Inv: func /(a bigrat) bigrat
+func (a Bigrat) Gop_Inv() Bigrat {
+	return Bigrat{tmprat1(a).Inv(a.Rat)}
+}
+
+// Gop_Add: func (a bigrat) += (b bigrat)
+func (a Bigrat) Gop_AddAssign(b Bigrat) {
+	a.Rat.Add(a.Rat, b.Rat)
+}
+
+// Gop_Sub: func (a bigrat) -= (b bigrat)
+func (a Bigrat) Gop_SubAssign(b Bigrat) {
+	a.Rat.Sub(a.Rat, b.Rat)
+}
+
+// Gop_Mul: func (a bigrat) *= (b bigrat)
+func (a Bigrat) Gop_MulAssign(b Bigrat) {
+	a.Rat.Mul(a.Rat, b.Rat)
+}
+
+// Gop_Quo: func (a bigrat) /= (b bigrat)
+func (a Bigrat) Gop_QuoAssign(b Bigrat) {
+	a.Rat.Quo(a.Rat, b.Rat)
+}
+
+// Bigrat_Cast: func bigrat() bigrat
+func Bigrat_Cast__0() Bigrat {
+	return Bigrat{new(big.Rat)}
+}
+
+// Bigrat_Cast: func bigrat(a bigint) bigrat
+func Bigrat_Cast__1(a Bigint) Bigrat {
+	return Bigrat{new(big.Rat).SetInt(a.Int)}
+}
+
+// Bigrat_Cast: func bigrat(a *big.Int) bigrat
+func Bigrat_Cast__2(a *big.Int) Bigrat {
+	return Bigrat{new(big.Rat).SetInt(a)}
+}
+
+// Bigrat_Cast: func bigrat(a, b int64) bigrat
+func Bigrat_Cast__3(a, b int64) Bigrat {
+	return Bigrat{big.NewRat(a, b)}
+}
+
+// Bigrat_Cast: func bigrat(a *big.Rat) bigrat
+func Bigrat_Cast__4(a *big.Rat) Bigrat {
+	return Bigrat{a}
+}
+
+// Bigrat_Init: func bigrat.init(x untyped_int) bigrat
+func Bigrat_Init__0(x int) Bigrat {
+	return Bigrat{big.NewRat(int64(x), 1)}
+}
+
+// Bigrat_Init: func bigrat.init(x untyped_bigint) bigrat
+func Bigrat_Init__1(x UntypedBigint) Bigrat {
+	return Bigrat{new(big.Rat).SetInt(x)}
+}
+
+// Bigrat_Init: func bigrat.init(x *big.Rat) bigrat
+func Bigrat_Init__2(x *big.Rat) Bigrat {
+	return Bigrat{x}
+}
+
+// -----------------------------------------------------------------------------
+// type bigfloat
+
+// A Bigfloat represents a multi-precision floating point number.
+// The zero value for a Float represents nil.
+type Bigfloat struct {
+	*big.Float
+}
+
+// -----------------------------------------------------------------------------
diff --git a/builtin/ng/uint128.go b/builtin/ng/uint128.go
index e591a182..b42be796 100644
--- a/builtin/ng/uint128.go
+++ b/builtin/ng/uint128.go
@@ -2,6 +2,7 @@ package ng
 
 import (
 	"fmt"
+	"log"
 	"math/big"
 	"math/bits"
 	"strconv"
@@ -16,6 +17,12 @@ const (
 	intSize   = 32 << (^uint(0) >> 63)
 )
 
+//
+// Gop_: Go+ object prefix
+// Gop_xxx_Cast: type Gop_xxx typecast
+// xxxx__N: the Nth overload function
+//
+
 type Gop_ninteger = uint
 
 // -----------------------------------------------------------------------------
@@ -24,7 +31,7 @@ type Uint128 struct {
 	hi, lo uint64
 }
 
-// Uint128_Cast: func uint128.init(v int) uint128
+// Uint128_Init: func uint128.init(v int) uint128
 func Uint128_Init__0(v int) (out Uint128) {
 	if v < 0 {
 		panic("TODO: can't init uint128 from a negative integer")
@@ -32,6 +39,15 @@ func Uint128_Init__0(v int) (out Uint128) {
 	return Uint128{lo: uint64(v)}
 }
 
+// Uint128_Init: func bigint.init(x *big.Int) bigint
+func Uint128_Init__1(v *big.Int) (out Uint128) {
+	out, inRange := Uint128_Cast__9(v)
+	if !inRange {
+		log.Panicf("value %v was not in valid uint128 range\n", v)
+	}
+	return
+}
+
 // Uint128_Cast: func uint128(hi, lo uint64) uint128
 func Uint128_Cast__0(hi, lo uint64) Uint128 {
 	return Uint128{hi: hi, lo: lo}
diff --git a/cl/builtin.go b/cl/builtin.go
index 8d4cbf59..0a5d5f15 100644
--- a/cl/builtin.go
+++ b/cl/builtin.go
@@ -27,17 +27,17 @@ import (
 
 func initMathBig(pkg gox.PkgImporter, conf *gox.Config, big *gox.PkgRef) {
 	big.EnsureImported()
-	conf.UntypedBigInt = big.Ref("UntypedInt").Type().(*types.Named)
-	conf.UntypedBigRat = big.Ref("UntypedRat").Type().(*types.Named)
-	conf.UntypedBigFloat = big.Ref("UntypedFloat").Type().(*types.Named)
+	conf.UntypedBigInt = big.Ref("UntypedBigint").Type().(*types.Named)
+	conf.UntypedBigRat = big.Ref("UntypedBigrat").Type().(*types.Named)
+	conf.UntypedBigFloat = big.Ref("UntypedBigfloat").Type().(*types.Named)
 }
 
-func initBuiltin(pkg gox.PkgImporter, builtin *types.Package, fmt, big, ng, buil *gox.PkgRef) {
+func initBuiltin(pkg gox.PkgImporter, builtin *types.Package, fmt, ng, buil *gox.PkgRef) {
 	scope := builtin.Scope()
-	typs := []string{"int", "rat", "float"}
+	typs := []string{"bigint", "bigrat", "bigfloat"}
 	for _, typ := range typs {
 		name := string(typ[0]-('a'-'A')) + typ[1:]
-		scope.Insert(types.NewTypeName(token.NoPos, builtin, "big"+typ, big.Ref(name).Type()))
+		scope.Insert(types.NewTypeName(token.NoPos, builtin, typ, ng.Ref(name).Type()))
 	}
 	fns := []string{
 		"print", "println", "printf", "errorf",
@@ -58,12 +58,11 @@ func newBuiltinDefault(pkg gox.PkgImporter, conf *gox.Config) *types.Package {
 	builtin := types.NewPackage("", "")
 	fmt := pkg.Import("fmt")
 	buil := pkg.Import("github.com/goplus/gop/builtin")
-	big := pkg.Import("github.com/goplus/gop/builtin/big")
 	ng := pkg.Import("github.com/goplus/gop/builtin/ng")
 	pkg.Import("strconv")
 	pkg.Import("strings")
-	initMathBig(pkg, conf, big)
-	initBuiltin(pkg, builtin, fmt, big, ng, buil)
+	initMathBig(pkg, conf, ng)
+	initBuiltin(pkg, builtin, fmt, ng, buil)
 	gox.InitBuiltin(pkg, builtin, conf)
 	return builtin
 }


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index e272dcd3..cadc4fe8 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -1224,10 +1224,10 @@ var x, y bigint
 var z bigint = x + y
 `, `package main
 
-import big "github.com/goplus/gop/builtin/big"
+import ng "github.com/goplus/gop/builtin/ng"
 
-var x, y big.Int
-var z big.Int = x.Gop_Add(y)
+var x, y ng.Bigint
+var z ng.Bigint = x.Gop_Add(y)
 `)
 }
 
@@ -1237,11 +1237,11 @@ var x = 1r
 `, `package main
 
 import (
-	big "github.com/goplus/gop/builtin/big"
-	big1 "math/big"
+	ng "github.com/goplus/gop/builtin/ng"
+	big "math/big"
 )
 
-var x = big.Int_Init__1(big1.NewInt(1))
+var x = ng.Bigint_Init__1(big.NewInt(1))
 `)
 }
 
@@ -1273,11 +1273,11 @@ var x = 1/2r
 `, `package main
 
 import (
-	big "github.com/goplus/gop/builtin/big"
-	big1 "math/big"
+	ng "github.com/goplus/gop/builtin/ng"
+	big "math/big"
 )
 
-var x = big.Rat_Init__2(big1.NewRat(1, 2))
+var x = ng.Bigrat_Init__2(big.NewRat(1, 2))
 `)
 }
 
@@ -1287,11 +1287,11 @@ var x = 3 + 1/2r
 `, `package main
 
 import (
-	big "github.com/goplus/gop/builtin/big"
-	big1 "math/big"
+	ng "github.com/goplus/gop/builtin/ng"
+	big "math/big"
 )
 
-var x = big.Rat_Init__2(big1.NewRat(7, 2))
+var x = ng.Bigrat_Init__2(big.NewRat(7, 2))
 `)
 }
 
@@ -1304,13 +1304,13 @@ var z = 100 + y
 `, `package main
 
 import (
-	big "github.com/goplus/gop/builtin/big"
-	big1 "math/big"
+	ng "github.com/goplus/gop/builtin/ng"
+	big "math/big"
 )
 
-var x = big.Rat_Init__2(big1.NewRat(7, 2))
-var y = x.Gop_Add(big.Rat_Init__0(100))
-var z = big.Rat_Init__0(100) + y
+var x = ng.Bigrat_Init__2(big.NewRat(7, 2))
+var y = x.Gop_Add(ng.Bigrat_Init__0(100))
+var z = ng.Bigrat_Init__0(100) + y
 `)
 }
 
@@ -1392,12 +1392,12 @@ var x bigint
 x += 3
 `, `package main
 
-import big "github.com/goplus/gop/builtin/big"
+import ng "github.com/goplus/gop/builtin/ng"
 
-var x big.Int
+var x ng.Bigint
 
 func main() {
-	x.Gop_AddAssign(big.Int_Init__0(3))
+	x.Gop_AddAssign(ng.Bigint_Init__0(3))
 }
 `)
 }
@@ -1409,13 +1409,13 @@ x *= 2
 `, `package main
 
 import (
-	big "github.com/goplus/gop/builtin/big"
-	big1 "math/big"
+	ng "github.com/goplus/gop/builtin/ng"
+	big "math/big"
 )
 
 func main() {
-	x := big.Int_Init__1(big1.NewInt(3))
-	x.Gop_MulAssign(big.Int_Init__0(2))
+	x := ng.Bigint_Init__1(big.NewInt(3))
+	x.Gop_MulAssign(ng.Bigint_Init__0(2))
 }
 `)
 }
@@ -1427,13 +1427,13 @@ x *= 2r
 `, `package main
 
 import (
-	big "github.com/goplus/gop/builtin/big"
-	big1 "math/big"
+	ng "github.com/goplus/gop/builtin/ng"
+	big "math/big"
 )
 
 func main() {
-	x := big.Int_Init__1(big1.NewInt(3))
-	x.Gop_MulAssign(big.Int_Init__1(big1.NewInt(2)))
+	x := ng.Bigint_Init__1(big.NewInt(3))
+	x.Gop_MulAssign(ng.Bigint_Init__1(big.NewInt(2)))
 }
 `)
 }
diff --git a/cl/run_test.go b/cl/run_test.go
index 0c36b020..a11958ed 100644
--- a/cl/run_test.go
+++ b/cl/run_test.go
@@ -117,6 +117,14 @@ println x
 `)
 }
 
+func _TestInt128_init(t *testing.T) {
+	testRun(t, `
+var x uint128 = 1 << 65
+println x
+`, `1
+`)
+}
+
 func TestInt128_printf(t *testing.T) {
 	testRun(t, `
 var x uint128 = 1