Source file src/go/printer/math.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package printer
     6  
     7  import "math"
     8  
     9  // log2ish returns a crude approximation to logâ‚‚(x).
    10  // The result is only used for heuristic alignment decisions and should
    11  // not be used where precision matters.
    12  // The approximation is guaranteed to produce identical results
    13  // across all architectures.
    14  func log2ish(x float64) float64 {
    15  	f, e := math.Frexp(x)
    16  	return float64(e) + 2*(f-1)
    17  }
    18  
    19  // exp2ish returns a crude approximation to 2**x.
    20  // The result is only used for heuristic alignment decisions and should
    21  // not be used where precision matters.
    22  // The approximation is guaranteed to produce identical results
    23  // across all architectures.
    24  func exp2ish(x float64) float64 {
    25  	n := math.Floor(x)
    26  	f := x - n
    27  	return math.Ldexp(1+f, int(n))
    28  }
    29  

View as plain text