Beispiel #1
0
func TestSqrt(t *testing.T) {
	numbers := []string{
		"93845895110924997939619620205961794350920309182366517272043413179685324014761",
		"69105835870199153467162210945784416638855243478241804950569679288538869324319",
		"98962852285157630260915782241836609413140230175083651803312834404919437446053",
		"36317938229605222802428943032353131143116755641174816538429154625143871344197",
		"34350266504989669203432549294422599219204587184049128615381495990495502309209",
		"18204849169635358408169482661313928794336132815120732872856773352186520943781",
		"9723547989068653705018929505866149012335913222247343211073612173133525296219",
		"82871077872852450664782155632268023043996476167345573065229622315492882980623",
		"22856450670839904203062539524939514231429034860506554613939398064780917006117",
		"1133028424325951536479152017902354822905940331016138739712579674465852496751",
		"66190348295371735778910813271715110278762226582449603965856760126883910115231",
		"67110703748429597893338674661673279865284238141342172221809893325337357465213",
		"67907826904909216076322754184715993424884161760995928759256942503051716644171",
		"76128483155619054801182538439486844205442146012173793296249561612451294050669",
		"77820156304482546934043298147893054920197524209952870273345573570345100056869",
		"114580143581984719060280282563142542662414835420671277376461092447281111712587",
	}
	for _, numStr := range numbers {
		n, _ := mathx.NewIntFromString(numStr, 10)
		m := n.Sqrt()
		m1 := m.Add(mathx.NewInt(1))
		if m.Mul(m).Cmp(n) >= 0 || m1.Mul(m1).Cmp(n) <= 0 {
			t.Errorf("Sqrt(%s) returned %s", n, m)
		}
	}
}
Beispiel #2
0
func setCoeff(coeffs []mathx.Int, degreeS, coeff string, neg bool) []mathx.Int {
	degree, _ := strconv.Atoi(degreeS)
	for degree >= len(coeffs) {
		coeffs = append(coeffs, *intZero)
	}
	c, _ := mathx.NewIntFromString(coeff, 10)
	if neg {
		c = c.Neg()
	}
	coeffs[degree] = *c
	return coeffs
}