Пример #1
0
// IsFundamentalDiscriminant returns true if the given discriminant is
// fundamental.
func IsFundamentalDiscriminant(D *mathx.Int) bool {
	d := D.Int64()
	absd := d
	if d < 0 {
		absd = -absd
	}
	if d == 1 {
		return true
	}
	if PosMod(d, 4) == 1 && IsSquareFree64(absd) {
		return true
	}
	if PosMod(d, 4) == 0 {
		if IsSquareFree64(absd / 4) {
			return PosMod(d/4, 4) == 2 || PosMod(d/4, 4) == 3
		}
	}
	return false
}
Пример #2
0
// String returns a kind messy decimal string version of this.
// It is utterly precise, and will use as many decimal digits
// as are necessary to completely represent this number.
func (f Float) String() string {
	sign := "+"
	if !f.sign {
		sign = "-"
	}

	var whole *mathx.Int
	var fraction *mathx.Int

	if f.exp <= 0 {
		whole = f.mantissa.Rsh(uint(-f.exp))
		fraction = f.mantissa.Sub(whole.Lsh(uint(-f.exp)))
	} else {
		whole = mathx.NewInt(0)
		fraction = f.mantissa
	}

	whole = f.mantissa.Rsh(uint(-f.exp))
	fraction = f.mantissa.Sub(whole.Lsh(uint(-f.exp)))

	digits := ""
	for fraction.Sign() != 0 {
		fraction = fraction.Mul64(10)
		digit := fraction.Rsh(uint(-f.exp))
		fraction = fraction.Sub(digit.Lsh(uint(-f.exp)))
		digits += digit.String()
	}
	if digits == "" {
		digits = "0"
	}
	return fmt.Sprintf("%s%s.%s", sign, whole.String(), digits)
}