Floating-point arithmetics
As described in previous recipes, the representation of the floating-point numbers also complicates the arithmetic. For general purposes, the operations on the built-in float64
are sufficient. In case more precision is needed, the math/big
package comes into play. This recipe will show you how to handle this.
How to do it...
- Open the console and create the folder
chapter03/recipe04
. - Navigate to the directory.
- Create the
main.go
file with the following content:
package main import ( "fmt" "math/big" ) const PI = `3.1415926535897932384626433832795028841971693 993751058209749445923078164062862089986280348253 421170679821480865132823066470938446095505822317 253594081284811174502841027019385211055596446229 4895493038196` const diameter = 3.0 const precision = 400 func main() { pi, _ := new(big.Float).SetPrec...