Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use go language to find the absolute value

Shulou Source: shulou.com Published: 2022-05-31 22:06:04 10月24日 Update

This article mainly explains "how to use go language to find the absolute value". Interested friends might as well take a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use the go language to find the absolute value"!

In the go language, you can use the abs () function in the math package to find the absolute value, the syntax format "math.Abs (x)", you can return the absolute value of the parameter x; the value type of the input and output of the abs () function is "float64".

In the go language, you can use the abs () function in the math package to find the absolute value.

Syntax:

Math.Abs (x float64)

Return value:

Abs returns the absolute value of x.

The special circumstances are:

Abs (±Inf) = + InfAbs (NaN) = NaN

Example

Package main import ("fmt"math") func main () {x: = math.Abs (- 2) fmt.Printf ("% .1f\ n", x) y: = math.Abs (2) fmt.Printf ("% .1f\ n", y)}

Extended data:

Some common methods under Golang math package

Package mainimport ("fmt"math") func main () {I: = 1 fmt.Println (math.Abs (float64 (I) / / take the absolute value fmt.Println (math.Ceil (3.8)) / / round up fmt.Println (math.Floor (3.6)) / / round down fmt.Println (math.Mod (11L3) ) / / the effect of taking the remainder 11% 3 is the same as fmt.Println (math.Modf (3.22)) / / the integer is the same as the decimal fmt.Println (math.Pow (3Power2)) / / the Y power of X (math.Pow10 (3)) / / the N power of fmt.Println (math.Sqrt (9)) / 10 ) / / Square 3 fmt.Println (math.Cbrt (8)) / / Square 2 fmt.Println (math.Pi) / / π fmt.Println (math.Round (4.2)) / / rounding fmt.Println (math.IsNaN (3.4)) / / false report whether f represents a NaN (Not A Number) value. Fmt.Println (math.Trunc (1.999999)) / / 1 returns the integer portion (the floating-point value of). Fmt.Println (math.Max (- 1.3,0) / / 0 returns the maximum value fmt.Println (math.Min (- 1.3,0)) / /-1.3 returns the minimum value fmt.Println (math.Dim (- 12,-19)) / / 7 function returns the maximum value fmt.Println (math.Dim (- 12) in x and y. ) / / 0 function returns fmt.Println (math.Cbrt (8)) / / 2 returns the cubic root of x (math.Hypot (3,4)) / / 5 returns Sqrt (math.Pow (2,8)) fmt.Println (math.Pow (2,8)) / / 256returns x ^ y}

Result

14323 0.220000000000000291000323.1415926535897934false10-1.37025256 so far, I believe you have a deeper understanding of "how to use the go language to find the absolute value". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Absolute value language function maximum maximum multiplier content integer method grammar learning practical deeper minimum special rounding remainder interest parameter practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Apple Huawei Shulou Information