Go language-numeric type

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

An integer type has unsigned and signed two types. Go supports both int and uint , the lengths of the two types are the same, but the exact length depends on the implementation of the different compilers. ~ ~ The current GCC and GCCGO compilers use 32-bit representation on both 32-bit and 64-bit int platforms uint , but may increase to 64 bits in the future on 64-bit platforms. Go also has a direct definition of the type of the number of digits:,,, rune int8 int16 int32 , int64 and byte , uint8 uint16 uint32 uint64 ,,,. Which rune is int32 the nickname, byte is uint8 the nickname.

It is important to note that these types of variables are not allowed to assign values or operations to each other, or will cause the compiler to error when compiling.

The code below will produce an error

var a int8

var b int32

C:=a + b

In addition, int is not interoperable with int32, although the length of int is three bit.

There are two types of floating-point numbers float32 float64 (no float type), and the default is float64 .

Is that all? No! Go also supports complex numbers. Its default type is complex128 (64-bit real number + 64-bit imaginary number). If smaller is required, there are also complex64 (32-bit real numbers + 32-bit imaginary number). In the form of a complex RE + IMi number, which RE is the real part, IM is the imaginary part, and the last i is the imaginary unit. Here is an example of using a complex number:

var c complex64 = 5+5i//output: (5+5i)fmt.Printf("Value is: %v", c)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.