GO語言"math/big"包中"Float.Add"類型的用法及代碼示例。
用法:
func(z *Float) Add(x, y *Float) *Float
將集合 z 添加到四舍五入的和 x+y 並返回 z。如果 z 的精度為 0,則在運算前將其更改為 x 或 y 的精度中的較大者。根據z的精度和舍入方式進行舍入; z 的準確度報告相對於精確(非四舍五入)結果的結果誤差。如果 x 和 y 是符號相反的無窮大,則使用 ErrNaN 添加Panics。在這種情況下,z 的值是未定義的。
例子:
package main
import (
"fmt"
"math/big"
)
func main() {
// Operate on numbers of different precision.
var x, y, z big.Float
x.SetInt64(1000) // x is automatically set to 64bit precision
y.SetFloat64(2.718281828) // y is automatically set to 53bit precision
z.SetPrec(32)
z.Add(&x, &y)
fmt.Printf("x = %.10g (%s, prec = %d, acc = %s)\n", &x, x.Text('p', 0), x.Prec(), x.Acc())
fmt.Printf("y = %.10g (%s, prec = %d, acc = %s)\n", &y, y.Text('p', 0), y.Prec(), y.Acc())
fmt.Printf("z = %.10g (%s, prec = %d, acc = %s)\n", &z, z.Text('p', 0), z.Prec(), z.Acc())
}
輸出:
x = 1000 (0x.fap+10, prec = 64, acc = Exact) y = 2.718281828 (0x.adf85458248cd8p+2, prec = 53, acc = Exact) z = 1002.718282 (0x.faadf854p+10, prec = 32, acc = Below)
相關用法
- GO Float.SetString用法及代碼示例
- GO Float.Scan用法及代碼示例
- GO Float.Cmp用法及代碼示例
- GO Float64s用法及代碼示例
- GO Float64sAreSorted用法及代碼示例
- GO Float用法及代碼示例
- GO Floor用法及代碼示例
- GO Fscanln用法及代碼示例
- GO FileServer用法及代碼示例
- GO FieldsFunc用法及代碼示例
- GO Fprintln用法及代碼示例
- GO FormatMediaType用法及代碼示例
- GO Fprintf用法及代碼示例
- GO Fprint用法及代碼示例
- GO FormatUint用法及代碼示例
- GO FormatBool用法及代碼示例
- GO FormatFloat用法及代碼示例
- GO FileMode用法及代碼示例
- GO FullRune用法及代碼示例
- GO FullRuneInString用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Float.Add。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。