Source file 
src/math/example_test.go
     1  
     2  
     3  
     4  
     5  package math_test
     6  
     7  import (
     8  	"fmt"
     9  	"math"
    10  )
    11  
    12  func ExampleAcos() {
    13  	fmt.Printf("%.2f", math.Acos(1))
    14  	
    15  }
    16  
    17  func ExampleAcosh() {
    18  	fmt.Printf("%.2f", math.Acosh(1))
    19  	
    20  }
    21  
    22  func ExampleAsin() {
    23  	fmt.Printf("%.2f", math.Asin(0))
    24  	
    25  }
    26  
    27  func ExampleAsinh() {
    28  	fmt.Printf("%.2f", math.Asinh(0))
    29  	
    30  }
    31  
    32  func ExampleAtan() {
    33  	fmt.Printf("%.2f", math.Atan(0))
    34  	
    35  }
    36  
    37  func ExampleAtan2() {
    38  	fmt.Printf("%.2f", math.Atan2(0, 0))
    39  	
    40  }
    41  
    42  func ExampleAtanh() {
    43  	fmt.Printf("%.2f", math.Atanh(0))
    44  	
    45  }
    46  
    47  func ExampleCopysign() {
    48  	fmt.Printf("%.2f", math.Copysign(3.2, -1))
    49  	
    50  }
    51  
    52  func ExampleCos() {
    53  	fmt.Printf("%.2f", math.Cos(math.Pi/2))
    54  	
    55  }
    56  
    57  func ExampleCosh() {
    58  	fmt.Printf("%.2f", math.Cosh(0))
    59  	
    60  }
    61  
    62  func ExampleSin() {
    63  	fmt.Printf("%.2f", math.Sin(math.Pi))
    64  	
    65  }
    66  
    67  func ExampleSincos() {
    68  	sin, cos := math.Sincos(0)
    69  	fmt.Printf("%.2f, %.2f", sin, cos)
    70  	
    71  }
    72  
    73  func ExampleSinh() {
    74  	fmt.Printf("%.2f", math.Sinh(0))
    75  	
    76  }
    77  
    78  func ExampleTan() {
    79  	fmt.Printf("%.2f", math.Tan(0))
    80  	
    81  }
    82  
    83  func ExampleTanh() {
    84  	fmt.Printf("%.2f", math.Tanh(0))
    85  	
    86  }
    87  
    88  func ExampleSqrt() {
    89  	const (
    90  		a = 3
    91  		b = 4
    92  	)
    93  	c := math.Sqrt(a*a + b*b)
    94  	fmt.Printf("%.1f", c)
    95  	
    96  }
    97  
    98  func ExampleCeil() {
    99  	c := math.Ceil(1.49)
   100  	fmt.Printf("%.1f", c)
   101  	
   102  }
   103  
   104  func ExampleFloor() {
   105  	c := math.Floor(1.51)
   106  	fmt.Printf("%.1f", c)
   107  	
   108  }
   109  
   110  func ExamplePow() {
   111  	c := math.Pow(2, 3)
   112  	fmt.Printf("%.1f", c)
   113  	
   114  }
   115  
   116  func ExamplePow10() {
   117  	c := math.Pow10(2)
   118  	fmt.Printf("%.1f", c)
   119  	
   120  }
   121  
   122  func ExampleRound() {
   123  	p := math.Round(10.5)
   124  	fmt.Printf("%.1f\n", p)
   125  
   126  	n := math.Round(-10.5)
   127  	fmt.Printf("%.1f\n", n)
   128  	
   129  	
   130  	
   131  }
   132  
   133  func ExampleRoundToEven() {
   134  	u := math.RoundToEven(11.5)
   135  	fmt.Printf("%.1f\n", u)
   136  
   137  	d := math.RoundToEven(12.5)
   138  	fmt.Printf("%.1f\n", d)
   139  	
   140  	
   141  	
   142  }
   143  
   144  func ExampleLog() {
   145  	x := math.Log(1)
   146  	fmt.Printf("%.1f\n", x)
   147  
   148  	y := math.Log(2.7183)
   149  	fmt.Printf("%.1f\n", y)
   150  	
   151  	
   152  	
   153  }
   154  
   155  func ExampleLog2() {
   156  	fmt.Printf("%.1f", math.Log2(256))
   157  	
   158  }
   159  
   160  func ExampleLog10() {
   161  	fmt.Printf("%.1f", math.Log10(100))
   162  	
   163  }
   164  
   165  func ExampleRemainder() {
   166  	fmt.Printf("%.1f", math.Remainder(100, 30))
   167  	
   168  }
   169  
   170  func ExampleMod() {
   171  	c := math.Mod(7, 4)
   172  	fmt.Printf("%.1f", c)
   173  	
   174  }
   175  
   176  func ExampleAbs() {
   177  	x := math.Abs(-2)
   178  	fmt.Printf("%.1f\n", x)
   179  
   180  	y := math.Abs(2)
   181  	fmt.Printf("%.1f\n", y)
   182  	
   183  	
   184  	
   185  }
   186  func ExampleDim() {
   187  	fmt.Printf("%.2f\n", math.Dim(4, -2))
   188  	fmt.Printf("%.2f\n", math.Dim(-4, 2))
   189  	
   190  	
   191  	
   192  }
   193  
   194  func ExampleExp() {
   195  	fmt.Printf("%.2f\n", math.Exp(1))
   196  	fmt.Printf("%.2f\n", math.Exp(2))
   197  	fmt.Printf("%.2f\n", math.Exp(-1))
   198  	
   199  	
   200  	
   201  	
   202  }
   203  
   204  func ExampleExp2() {
   205  	fmt.Printf("%.2f\n", math.Exp2(1))
   206  	fmt.Printf("%.2f\n", math.Exp2(-3))
   207  	
   208  	
   209  	
   210  }
   211  
   212  func ExampleExpm1() {
   213  	fmt.Printf("%.6f\n", math.Expm1(0.01))
   214  	fmt.Printf("%.6f\n", math.Expm1(-1))
   215  	
   216  	
   217  	
   218  }
   219  
   220  func ExampleTrunc() {
   221  	fmt.Printf("%.2f\n", math.Trunc(math.Pi))
   222  	fmt.Printf("%.2f\n", math.Trunc(-1.2345))
   223  	
   224  	
   225  	
   226  }
   227  
   228  func ExampleCbrt() {
   229  	fmt.Printf("%.2f\n", math.Cbrt(8))
   230  	fmt.Printf("%.2f\n", math.Cbrt(27))
   231  	
   232  	
   233  	
   234  }
   235  
   236  func ExampleModf() {
   237  	int, frac := math.Modf(3.14)
   238  	fmt.Printf("%.2f, %.2f\n", int, frac)
   239  
   240  	int, frac = math.Modf(-2.71)
   241  	fmt.Printf("%.2f, %.2f\n", int, frac)
   242  	
   243  	
   244  	
   245  }
   246  
View as plain text