Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use go language to find the absolute value

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report