zoukankan      html  css  js  c++  java
  • 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
    
    */
    
    
  • 相关阅读:
    JavaScript闭包 懂不懂由你反正我是懂了
    浅析对象访问属性的"."和"[]"方法区别
    PHP:6种GET和POST请求发送方法
    ArcThemALL!5.1:解压、脱壳、压缩样样精通
    nw.exe开发DEMO下载
    解析Javascript事件冒泡机制
    node.js之fs模块
    Node.js读取文件内容
    php-编译模块1
    jenkins--使用命令行自动启动Jenkins的job
  • 原文地址:https://www.cnblogs.com/zrdpy/p/8620755.html
Copyright © 2011-2022 走看看