X7ROOT File Manager
Current Path:
/opt/golang/1.22.0/src/math/big
opt
/
golang
/
1.22.0
/
src
/
math
/
big
/
๐
..
๐
accuracy_string.go
(647 B)
๐
alias_test.go
(8.81 KB)
๐
arith.go
(8.28 KB)
๐
arith_386.s
(4.04 KB)
๐
arith_amd64.go
(278 B)
๐
arith_amd64.s
(9.07 KB)
๐
arith_arm.s
(4 KB)
๐
arith_arm64.s
(11.85 KB)
๐
arith_decl.go
(686 B)
๐
arith_decl_pure.go
(1.01 KB)
๐
arith_decl_s390x.go
(503 B)
๐
arith_loong64.s
(749 B)
๐
arith_mips64x.s
(763 B)
๐
arith_mipsx.s
(759 B)
๐
arith_ppc64x.s
(16.4 KB)
๐
arith_riscv64.s
(750 B)
๐
arith_s390x.s
(20.29 KB)
๐
arith_s390x_test.go
(770 B)
๐
arith_test.go
(19.88 KB)
๐
arith_wasm.s
(613 B)
๐
bits_test.go
(5.07 KB)
๐
calibrate_test.go
(4.63 KB)
๐
decimal.go
(6.63 KB)
๐
decimal_test.go
(3.33 KB)
๐
doc.go
(3.8 KB)
๐
example_rat_test.go
(1.68 KB)
๐
example_test.go
(4.05 KB)
๐
float.go
(44.55 KB)
๐
float_test.go
(51.94 KB)
๐
floatconv.go
(8.35 KB)
๐
floatconv_test.go
(24.27 KB)
๐
floatexample_test.go
(3.63 KB)
๐
floatmarsh.go
(3.65 KB)
๐
floatmarsh_test.go
(4.51 KB)
๐
ftoa.go
(13.5 KB)
๐
gcd_test.go
(2.16 KB)
๐
hilbert_test.go
(2.88 KB)
๐
int.go
(33.21 KB)
๐
int_test.go
(58.47 KB)
๐
intconv.go
(6.7 KB)
๐
intconv_test.go
(10.01 KB)
๐
intmarsh.go
(2.19 KB)
๐
intmarsh_test.go
(3.07 KB)
๐
link_test.go
(1.4 KB)
๐
nat.go
(31.81 KB)
๐
nat_test.go
(26.22 KB)
๐
natconv.go
(14.56 KB)
๐
natconv_test.go
(16.85 KB)
๐
natdiv.go
(34.36 KB)
๐
prime.go
(10.39 KB)
๐
prime_test.go
(7.1 KB)
๐
rat.go
(13.48 KB)
๐
rat_test.go
(18.89 KB)
๐
ratconv.go
(12.35 KB)
๐
ratconv_test.go
(19.31 KB)
๐
ratmarsh.go
(2.23 KB)
๐
ratmarsh_test.go
(3.34 KB)
๐
roundingmode_string.go
(819 B)
๐
sqrt.go
(2.79 KB)
๐
sqrt_test.go
(4.81 KB)
Editing: sqrt.go
// Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package big import ( "math" "sync" ) var threeOnce struct { sync.Once v *Float } func three() *Float { threeOnce.Do(func() { threeOnce.v = NewFloat(3.0) }) return threeOnce.v } // Sqrt sets z to the rounded square root of x, and returns it. // // If z's precision is 0, it is changed to x's precision before the // operation. Rounding is performed according to z's precision and // rounding mode, but z's accuracy is not computed. Specifically, the // result of z.Acc() is undefined. // // The function panics if z < 0. The value of z is undefined in that // case. func (z *Float) Sqrt(x *Float) *Float { if debugFloat { x.validate() } if z.prec == 0 { z.prec = x.prec } if x.Sign() == -1 { // following IEEE754-2008 (section 7.2) panic(ErrNaN{"square root of negative operand"}) } // handle ยฑ0 and +โ if x.form != finite { z.acc = Exact z.form = x.form z.neg = x.neg // IEEE754-2008 requires โยฑ0 = ยฑ0 return z } // MantExp sets the argument's precision to the receiver's, and // when z.prec > x.prec this will lower z.prec. Restore it after // the MantExp call. prec := z.prec b := x.MantExp(z) z.prec = prec // Compute โ(zยท2**b) as // โ( z)ยท2**(ยฝb) if b is even // โ(2z)ยท2**(โยฝbโ) if b > 0 is odd // โ(ยฝz)ยท2**(โยฝbโ) if b < 0 is odd switch b % 2 { case 0: // nothing to do case 1: z.exp++ case -1: z.exp-- } // 0.25 <= z < 2.0 // Solving 1/xยฒ - z = 0 avoids Quo calls and is faster, especially // for high precisions. z.sqrtInverse(z) // re-attach halved exponent return z.SetMantExp(z, b/2) } // Compute โx (to z.prec precision) by solving // // 1/tยฒ - x = 0 // // for t (using Newton's method), and then inverting. func (z *Float) sqrtInverse(x *Float) { // let // f(t) = 1/tยฒ - x // then // g(t) = f(t)/f'(t) = -ยฝt(1 - xtยฒ) // and the next guess is given by // t2 = t - g(t) = ยฝt(3 - xtยฒ) u := newFloat(z.prec) v := newFloat(z.prec) three := three() ng := func(t *Float) *Float { u.prec = t.prec v.prec = t.prec u.Mul(t, t) // u = tยฒ u.Mul(x, u) // = xtยฒ v.Sub(three, u) // v = 3 - xtยฒ u.Mul(t, v) // u = t(3 - xtยฒ) u.exp-- // = ยฝt(3 - xtยฒ) return t.Set(u) } xf, _ := x.Float64() sqi := newFloat(z.prec) sqi.SetFloat64(1 / math.Sqrt(xf)) for prec := z.prec + 32; sqi.prec < prec; { sqi.prec *= 2 sqi = ng(sqi) } // sqi = 1/โx // x/โx = โx z.Mul(x, sqi) } // newFloat returns a new *Float with space for twice the given // precision. func newFloat(prec2 uint32) *Float { z := new(Float) // nat.make ensures the slice length is > 0 z.mant = z.mant.make(int(prec2/_W) * 2) return z }
Upload File
Create Folder