3.2 Floating-Point Numbers
Go provides two sizes of floating-point numbers, float32
and
float64
.
Their arithmetic properties are governed by the IEEE 754 standard
implemented by all modern CPUs.
Values of these numeric types range from tiny to huge.
The limits of floating-point values can be found in the math
package.
The constant math.MaxFloat32
, the largest float32
, is
about 3.4e38
, and math.MaxFloat64
is about 1.8e308
.
The smallest
positive values are near 1.4e-45
and 4.9e-324
, respectively.
A float32
provides approximately six decimal digits of precision, whereas
a float64
provides about 15 digits; float64
should be preferred for
most purposes because float32
computations accumulate error rapidly unless one is quite careful, and ...
Get The Go Programming Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.