登录
首页 >  Golang >  Go问答

Go 规范中对于“无符号”、“有符号”和“虚数”数字的定义是什么?

来源:stackoverflow

时间:2024-02-14 14:03:25 270浏览 收藏

哈喽!大家好,很高兴又见面了,我是golang学习网的一名作者,今天由我给大家带来一篇《Go 规范中对于“无符号”、“有符号”和“虚数”数字的定义是什么?》,本文主要会讲到等等知识点,希望大家一起学习进步,也欢迎大家关注、点赞、收藏、转发! 下面就一起来看看吧!

问题内容

go中有一个关于数字类型的部分,但我不太清楚其中的一些定义。在这种情况下,“无符号”、“所有有符号的集合”、“虚部”意味着什么?

uint8       the set of all unsigned  8-bit integers (0 to 255)
uint16      the set of all unsigned 16-bit integers (0 to 65535)
uint32      the set of all unsigned 32-bit integers (0 to 4294967295)
uint64      the set of all unsigned 64-bit integers (0 to 18446744073709551615)

int8        the set of all signed  8-bit integers (-128 to 127)
int16       the set of all signed 16-bit integers (-32768 to 32767)
int32       the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64       the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

float32     the set of all IEEE-754 32-bit floating-point numbers
float64     the set of all IEEE-754 64-bit floating-point numbers

complex64   the set of all complex numbers with float32 real and imaginary parts
complex128  the set of all complex numbers with float64 real and imaginary parts

byte        alias for uint8
rune        alias for int32

参考:https://golang.org/ref/spec#numeric_types


解决方案


var x Complex128 = Complex(1, 2) // 1+2i

复数的最大值:complex128(1.7976931348623157e+308 + 1.7976931348623157e+308 i)

如果你熟悉复数,那么你就能理解它。否则此处 i = (-1) 的 root 或 i^2 = -1

无符号表示仅包含正数和 0。

uint64 范围 0 到 18,446,744,073,709,551,615

uint32 范围 0 到 4,294,967,295

而signed的set表示负数到正数的总范围

好了,本文到此结束,带大家了解了《Go 规范中对于“无符号”、“有符号”和“虚数”数字的定义是什么?》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>