• 3.4 最大浮点数?


    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
    ", circumference)
    	fmt.Printf("Circumference float64   = %.100f
    ", pi64*diameter)
    
    	sum := new(big.Float).Add(pi, pi)
    	fmt.Printf("Sum = %.100f
    ", sum)
    
    	diff := new(big.Float).Sub(pi, pi)
    	fmt.Printf("Diff = %.100f
    ", diff)
    
    	quo := new(big.Float).Quo(pi, pi)
    	fmt.Printf("Quocient = %.100f
    ", 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
    
    */
    
    
  • 相关阅读:
    Java常用的7大排序算法汇总
    swift 内存管理,WEAK 和 UNOWNED
    Java关键字final、static使用总结
    Swift对面向对象提供了良好的支持,下面介绍几个其独有的特性。
    如何自己动手实现 KVO(转)
    Method Swizzling 和 AOP 实践(转)
    Objective-C Runtime(转)
    在多线程中进行UI操作
    iOS 详解NSXMLParser方法解析XML数据方法
    用一张日落照片估算出地球的半径
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8620755.html
Copyright © 2020-2023  润新知