码迷,mamicode.com
首页 > 其他好文 > 详细

3.4 最大浮点数?

时间:2018-03-22 01:48:10      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:add   code   iam   span   pack   div   浮点数   pac   1.0   

package main

import (
    "fmt"
    "math"
    "math/big"
)

const PI = `3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196`
const diameter = 3.0
const precision = 400

func main() {

    pi, _ := new(big.Float).SetPrec(precision).SetString(PI)
    d := new(big.Float).SetPrec(precision).SetFloat64(diameter)

    circumference := new(big.Float).Mul(pi, d)

    pi64, _ := pi.Float64()
    fmt.Printf("Circumference big.Float = %.100f\n", circumference)
    fmt.Printf("Circumference float64   = %.100f\n", pi64*diameter)

    sum := new(big.Float).Add(pi, pi)
    fmt.Printf("Sum = %.100f\n", sum)

    diff := new(big.Float).Sub(pi, pi)
    fmt.Printf("Diff = %.100f\n", diff)

    quo := new(big.Float).Quo(pi, pi)
    fmt.Printf("Quocient = %.100f\n", quo)

}

// Round returns the nearest integer.
func Round(x float64) float64 {
    t := math.Trunc(x)
    if math.Abs(x-t) >= 0.5 {
        return t + math.Copysign(1, x)
    }
    return t
}

/*
Circumference big.Float = 9.4247779607693797153879301498385086525915081981253174629248337769234492188586269958841044760263512039
Circumference float64   = 9.4247779607693793479938904056325554847717285156250000000000000000000000000000000000000000000000000000
Sum = 6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341360
Diff = 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Quocient = 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

*/

3.4 最大浮点数?

标签:add   code   iam   span   pack   div   浮点数   pac   1.0   

原文地址:https://www.cnblogs.com/zrdpy/p/8620755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!