| | |
| | |
| | |
| |
|
| | package math_test |
| |
|
| | import ( |
| | "fmt" |
| | "math" |
| | ) |
| |
|
| | func ExampleAcos() { |
| | fmt.Printf("%.2f", math.Acos(1)) |
| | |
| | } |
| |
|
| | func ExampleAcosh() { |
| | fmt.Printf("%.2f", math.Acosh(1)) |
| | |
| | } |
| |
|
| | func ExampleAsin() { |
| | fmt.Printf("%.2f", math.Asin(0)) |
| | |
| | } |
| |
|
| | func ExampleAsinh() { |
| | fmt.Printf("%.2f", math.Asinh(0)) |
| | |
| | } |
| |
|
| | func ExampleAtan() { |
| | fmt.Printf("%.2f", math.Atan(0)) |
| | |
| | } |
| |
|
| | func ExampleAtan2() { |
| | fmt.Printf("%.2f", math.Atan2(0, 0)) |
| | |
| | } |
| |
|
| | func ExampleAtanh() { |
| | fmt.Printf("%.2f", math.Atanh(0)) |
| | |
| | } |
| |
|
| | func ExampleCopysign() { |
| | fmt.Printf("%.2f", math.Copysign(3.2, -1)) |
| | |
| | } |
| |
|
| | func ExampleCos() { |
| | fmt.Printf("%.2f", math.Cos(math.Pi/2)) |
| | |
| | } |
| |
|
| | func ExampleCosh() { |
| | fmt.Printf("%.2f", math.Cosh(0)) |
| | |
| | } |
| |
|
| | func ExampleSin() { |
| | fmt.Printf("%.2f", math.Sin(math.Pi)) |
| | |
| | } |
| |
|
| | func ExampleSincos() { |
| | sin, cos := math.Sincos(0) |
| | fmt.Printf("%.2f, %.2f", sin, cos) |
| | |
| | } |
| |
|
| | func ExampleSinh() { |
| | fmt.Printf("%.2f", math.Sinh(0)) |
| | |
| | } |
| |
|
| | func ExampleTan() { |
| | fmt.Printf("%.2f", math.Tan(0)) |
| | |
| | } |
| |
|
| | func ExampleTanh() { |
| | fmt.Printf("%.2f", math.Tanh(0)) |
| | |
| | } |
| |
|
| | func ExampleSqrt() { |
| | const ( |
| | a = 3 |
| | b = 4 |
| | ) |
| | c := math.Sqrt(a*a + b*b) |
| | fmt.Printf("%.1f", c) |
| | |
| | } |
| |
|
| | func ExampleCeil() { |
| | c := math.Ceil(1.49) |
| | fmt.Printf("%.1f", c) |
| | |
| | } |
| |
|
| | func ExampleFloor() { |
| | c := math.Floor(1.51) |
| | fmt.Printf("%.1f", c) |
| | |
| | } |
| |
|
| | func ExamplePow() { |
| | c := math.Pow(2, 3) |
| | fmt.Printf("%.1f", c) |
| | |
| | } |
| |
|
| | func ExamplePow10() { |
| | c := math.Pow10(2) |
| | fmt.Printf("%.1f", c) |
| | |
| | } |
| |
|
| | func ExampleRound() { |
| | p := math.Round(10.5) |
| | fmt.Printf("%.1f\n", p) |
| |
|
| | n := math.Round(-10.5) |
| | fmt.Printf("%.1f\n", n) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleRoundToEven() { |
| | u := math.RoundToEven(11.5) |
| | fmt.Printf("%.1f\n", u) |
| |
|
| | d := math.RoundToEven(12.5) |
| | fmt.Printf("%.1f\n", d) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleLog() { |
| | x := math.Log(1) |
| | fmt.Printf("%.1f\n", x) |
| |
|
| | y := math.Log(2.7183) |
| | fmt.Printf("%.1f\n", y) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleLog2() { |
| | fmt.Printf("%.1f", math.Log2(256)) |
| | |
| | } |
| |
|
| | func ExampleLog10() { |
| | fmt.Printf("%.1f", math.Log10(100)) |
| | |
| | } |
| |
|
| | func ExampleRemainder() { |
| | fmt.Printf("%.1f", math.Remainder(100, 30)) |
| | |
| | } |
| |
|
| | func ExampleMod() { |
| | c := math.Mod(7, 4) |
| | fmt.Printf("%.1f", c) |
| | |
| | } |
| |
|
| | func ExampleAbs() { |
| | x := math.Abs(-2) |
| | fmt.Printf("%.1f\n", x) |
| |
|
| | y := math.Abs(2) |
| | fmt.Printf("%.1f\n", y) |
| | |
| | |
| | |
| | } |
| | func ExampleDim() { |
| | fmt.Printf("%.2f\n", math.Dim(4, -2)) |
| | fmt.Printf("%.2f\n", math.Dim(-4, 2)) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleExp() { |
| | fmt.Printf("%.2f\n", math.Exp(1)) |
| | fmt.Printf("%.2f\n", math.Exp(2)) |
| | fmt.Printf("%.2f\n", math.Exp(-1)) |
| | |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleExp2() { |
| | fmt.Printf("%.2f\n", math.Exp2(1)) |
| | fmt.Printf("%.2f\n", math.Exp2(-3)) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleExpm1() { |
| | fmt.Printf("%.6f\n", math.Expm1(0.01)) |
| | fmt.Printf("%.6f\n", math.Expm1(-1)) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleTrunc() { |
| | fmt.Printf("%.2f\n", math.Trunc(math.Pi)) |
| | fmt.Printf("%.2f\n", math.Trunc(-1.2345)) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleCbrt() { |
| | fmt.Printf("%.2f\n", math.Cbrt(8)) |
| | fmt.Printf("%.2f\n", math.Cbrt(27)) |
| | |
| | |
| | |
| | } |
| |
|
| | func ExampleModf() { |
| | int, frac := math.Modf(3.14) |
| | fmt.Printf("%.2f, %.2f\n", int, frac) |
| |
|
| | int, frac = math.Modf(-2.71) |
| | fmt.Printf("%.2f, %.2f\n", int, frac) |
| | |
| | |
| | |
| | } |
| |
|