Source file src/internal/strconv/math_test.go

     1  // Copyright 2025 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 strconv_test
     6  
     7  import (
     8  	"math"
     9  	"testing"
    10  )
    11  
    12  func TestLog10Pow2(t *testing.T) {
    13  	for x := -1600; x <= +1600; x++ {
    14  		iMath := log10Pow2(x)
    15  		fMath := int(math.Floor(float64(x) * math.Ln2 / math.Ln10))
    16  		if iMath != fMath {
    17  			t.Errorf("log10Pow2(%d) = %d, want %d\n", x, iMath, fMath)
    18  		}
    19  	}
    20  }
    21  
    22  func TestLog2Pow10(t *testing.T) {
    23  	for x := -500; x <= +500; x++ {
    24  		iMath := log2Pow10(x)
    25  		fMath := int(math.Floor(float64(x) * math.Ln10 / math.Ln2))
    26  		if iMath != fMath {
    27  			t.Errorf("log2Pow10(%d) = %d, want %d\n", x, iMath, fMath)
    28  		}
    29  	}
    30  }
    31  

View as plain text