mirror of
https://github.com/gonum/gonum.git
synced 2025-10-18 21:15:23 +08:00
all: run gofmt and generate all packages
Changes made in dsp/fourier/internal/fftpack break the formatting used there, so these are reverted. There will be complaints in CI. [git-generate] gofmt -w . go generate gonum.org/v1/gonum/blas go generate gonum.org/v1/gonum/blas/gonum go generate gonum.org/v1/gonum/unit go generate gonum.org/v1/gonum/unit/constant go generate gonum.org/v1/gonum/graph/formats/dot go generate gonum.org/v1/gonum/graph/formats/rdf go generate gonum.org/v1/gonum/stat/card git checkout -- dsp/fourier/internal/fftpack
This commit is contained in:
@@ -178,64 +178,66 @@ func TestSqrt(t *testing.T) {
|
||||
//
|
||||
// __ieee754_sqrt(x)
|
||||
// Return correctly rounded sqrt.
|
||||
// -----------------------------------------
|
||||
// | Use the hardware sqrt if you have one |
|
||||
// -----------------------------------------
|
||||
//
|
||||
// -----------------------------------------
|
||||
// | Use the hardware sqrt if you have one |
|
||||
// -----------------------------------------
|
||||
//
|
||||
// Method:
|
||||
// Bit by bit method using integer arithmetic. (Slow, but portable)
|
||||
// 1. Normalization
|
||||
// Scale x to y in [1,4) with even powers of 2:
|
||||
// find an integer k such that 1 <= (y=x*2**(2k)) < 4, then
|
||||
// sqrt(x) = 2**k * sqrt(y)
|
||||
// 2. Bit by bit computation
|
||||
// Let q = sqrt(y) truncated to i bit after binary point (q = 1),
|
||||
// i 0
|
||||
// i+1 2
|
||||
// s = 2*q , and y = 2 * ( y - q ). (1)
|
||||
// i i i i
|
||||
//
|
||||
// To compute q from q , one checks whether
|
||||
// i+1 i
|
||||
// Bit by bit method using integer arithmetic. (Slow, but portable)
|
||||
// 1. Normalization
|
||||
// Scale x to y in [1,4) with even powers of 2:
|
||||
// find an integer k such that 1 <= (y=x*2**(2k)) < 4, then
|
||||
// sqrt(x) = 2**k * sqrt(y)
|
||||
// 2. Bit by bit computation
|
||||
// Let q = sqrt(y) truncated to i bit after binary point (q = 1),
|
||||
// i 0
|
||||
// i+1 2
|
||||
// s = 2*q , and y = 2 * ( y - q ). (1)
|
||||
// i i i i
|
||||
//
|
||||
// -(i+1) 2
|
||||
// (q + 2 ) <= y. (2)
|
||||
// i
|
||||
// -(i+1)
|
||||
// If (2) is false, then q = q ; otherwise q = q + 2 .
|
||||
// i+1 i i+1 i
|
||||
// To compute q from q , one checks whether
|
||||
// i+1 i
|
||||
//
|
||||
// With some algebraic manipulation, it is not difficult to see
|
||||
// that (2) is equivalent to
|
||||
// -(i+1)
|
||||
// s + 2 <= y (3)
|
||||
// i i
|
||||
// -(i+1) 2
|
||||
// (q + 2 ) <= y. (2)
|
||||
// i
|
||||
// -(i+1)
|
||||
// If (2) is false, then q = q ; otherwise q = q + 2 .
|
||||
// i+1 i i+1 i
|
||||
//
|
||||
// The advantage of (3) is that s and y can be computed by
|
||||
// i i
|
||||
// the following recurrence formula:
|
||||
// if (3) is false
|
||||
// With some algebraic manipulation, it is not difficult to see
|
||||
// that (2) is equivalent to
|
||||
// -(i+1)
|
||||
// s + 2 <= y (3)
|
||||
// i i
|
||||
//
|
||||
// s = s , y = y ; (4)
|
||||
// i+1 i i+1 i
|
||||
// The advantage of (3) is that s and y can be computed by
|
||||
// i i
|
||||
// the following recurrence formula:
|
||||
// if (3) is false
|
||||
//
|
||||
// otherwise,
|
||||
// -i -(i+1)
|
||||
// s = s + 2 , y = y - s - 2 (5)
|
||||
// i+1 i i+1 i i
|
||||
// s = s , y = y ; (4)
|
||||
// i+1 i i+1 i
|
||||
//
|
||||
// One may easily use induction to prove (4) and (5).
|
||||
// Note. Since the left hand side of (3) contain only i+2 bits,
|
||||
// it does not necessary to do a full (53-bit) comparison
|
||||
// in (3).
|
||||
// 3. Final rounding
|
||||
// After generating the 53 bits result, we compute one more bit.
|
||||
// Together with the remainder, we can decide whether the
|
||||
// result is exact, bigger than 1/2ulp, or less than 1/2ulp
|
||||
// (it will never equal to 1/2ulp).
|
||||
// The rounding mode can be detected by checking whether
|
||||
// huge + tiny is equal to huge, and whether huge - tiny is
|
||||
// equal to huge for some floating point number "huge" and "tiny".
|
||||
// otherwise,
|
||||
// -i -(i+1)
|
||||
// s = s + 2 , y = y - s - 2 (5)
|
||||
// i+1 i i+1 i i
|
||||
//
|
||||
// One may easily use induction to prove (4) and (5).
|
||||
// Note. Since the left hand side of (3) contain only i+2 bits,
|
||||
// it does not necessary to do a full (53-bit) comparison
|
||||
// in (3).
|
||||
// 3. Final rounding
|
||||
// After generating the 53 bits result, we compute one more bit.
|
||||
// Together with the remainder, we can decide whether the
|
||||
// result is exact, bigger than 1/2ulp, or less than 1/2ulp
|
||||
// (it will never equal to 1/2ulp).
|
||||
// The rounding mode can be detected by checking whether
|
||||
// huge + tiny is equal to huge, and whether huge - tiny is
|
||||
// equal to huge for some floating point number "huge" and "tiny".
|
||||
func sqrt(x float32) float32 {
|
||||
// special cases
|
||||
switch {
|
||||
|
Reference in New Issue
Block a user