Golang datatypes: Difference between revisions
From wikinotes
No edit summary |
|||
Line 48: | Line 48: | ||
Slow, but handles numbers of any size. | Slow, but handles numbers of any size. | ||
</blockquote><!-- math/big --> | </blockquote><!-- math/big --> | ||
= Complex Numbers = | |||
<blockquote> | |||
Go lets you represent complex/imaginary numbers. | |||
<syntaxhighlight lang="go"> | |||
var num complex64 = 1 + 2i | |||
var num complex128 = 1 + 2i | |||
var num complex64 = 2i // alternative for 1 + 2i | |||
var num complex64 = complex(1, 2) // alternative for 1 + 2i | |||
</syntaxhighlight> | |||
You can also extract the complex/imaginary part of the number. | |||
<syntaxhighlight lang="go"> | |||
var num complex64 = 1 + 2i | |||
real(num) // the real number component | |||
imag(num) // the imaginary number component | |||
</syntaxhighlight> | |||
</blockquote><!-- Complex Numbers --> | |||
</blockquote><!-- Numeric --> | </blockquote><!-- Numeric --> | ||
Revision as of 17:26, 29 May 2022
Literal Types
"foo" // string 123 // int (cpu-arch dependent bitsize) 3.14 // float64 6.2e25 // float64
Text
Numeric
Integers
Integer sizes are expressed by their bit-size.
signed
int // (however many bits your CPU word-size is) int8 // 128 - 127 int16 // 32,768 - 32,767 int32 // 2,147,483,648 - 2,147,483,647 int64 // 9,223,372,036,854,775,808 - 9,223,372,036,854,775,807unsigned
uint // (however many bits your CPU word-size is) uint8 // 0 - 255 uint16 // 0 - 65,535 uint32 // 0 - 4,294,967,295 // uint64 does not existBytes
Same as
uint8
.math/big
Slow, but handles numbers of any size.
Complex Numbers
Go lets you represent complex/imaginary numbers.
var num complex64 = 1 + 2i var num complex128 = 1 + 2i var num complex64 = 2i // alternative for 1 + 2i var num complex64 = complex(1, 2) // alternative for 1 + 2iYou can also extract the complex/imaginary part of the number.
var num complex64 = 1 + 2i real(num) // the real number component imag(num) // the imaginary number component
Pointers
uintptr // a pointer of however many bits your CPU word-size is