...

/

Accurate Computations and the big Package

Accurate Computations and the big Package

This lesson discusses how Go ensures accurate computations in its program via the big package.

We'll cover the following...

A major problem

We know that programmatically performed floating-point computations are sometimes not accurate. If you use Go’s float64 type in floating-point numbers computation, the results are accurate to about 15 decimal digits, enough for most tasks. When computing with very big whole numbers, the range of the types int64 or uint64 might also be too small. In that case, float32 or float64 can be used if accuracy is not a concern, but if it is, we cannot use floating-point numbers because they are only represented in an approximated way in memory.

Solution provided by Go

For performing perfectly accurate computations with integer values Go provides the math/big package contained in math: big.Int for integers, big.Rat for rational numbers (these are numbers than can be represented by a ...