dtoa

package module
v0.0.0-...-f2f4576 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 1 Imported by: 1

README

dtoa

Build Status GoDoc

本ライブラリは浮動小数点数値をバイト列に変換する高速関数を提供します。

実装はMilo Yip氏のC++実装dtoa.hをGoに移植したものとなっています。

おまけでitoaの実装も含んでいます。

ベンチマーク

数値 小数点以下桁数 strconv.AppendFloat dtoa.Dtoa 速度差
1.1 全部 434 ns/op 173 ns/op 2.5倍
3.1415926535 全部 316 ns/op 272 ns/op 1.16倍
2.225073858507201e-308 1桁 15694 ns/op 325 ns/op 48.3倍

使い方

// strconv.FormatFloat()風
fmt.Println(string(dtoa.Dtoa(nil, 1.12345678, 5)))
// 1.12345

// strconv.AppendFloat()風
buf := []byte{}
buf = dtoa.Dtoa(buf, 0.1, 5)
buf = append(buf, ',')
buf = dtoa.Dtoa(buf, 0.2, 5)
fmt.Println(string(buf))
// 0.1,0.2

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dtoa

func Dtoa(buf []byte, value float64, maxDecimalPlaces int) []byte

func DtoaSimple

func DtoaSimple(buf []byte, value float64, maxDecimalPlaces int) []byte

func Grisu2

func Grisu2(buf []byte, value float64) ([]byte, int, int)

func I32toa

func I32toa(buf []byte, value int32) []byte

func I64toa

func I64toa(buf []byte, value int64) []byte

func Prettify

func Prettify(buf []byte, l, k, maxDecimalPlaces int) []byte

func PrettifySimple

func PrettifySimple(buf []byte, l, k, maxDecimalPlaces int) []byte

func U32toa

func U32toa(buf []byte, value uint32) []byte

func U64toa

func U64toa(buf []byte, value uint64) []byte

Types

type DiyFp

type DiyFp struct {
	// contains filtered or unexported fields
}

func DiyFpDouble

func DiyFpDouble(d float64) DiyFp

func GetCachedPower

func GetCachedPower(e int) (DiyFp, int)

func GetCachedPower10

func GetCachedPower10(exp int, outExp *int) DiyFp

func GetCachedPowerByIndex

func GetCachedPowerByIndex(index uint) DiyFp

func (DiyFp) Minus

func (df DiyFp) Minus(rhs DiyFp) DiyFp

func (DiyFp) Multiplication

func (df DiyFp) Multiplication(rhs DiyFp) DiyFp

func (DiyFp) Normalize

func (df DiyFp) Normalize() DiyFp

func (DiyFp) NormalizeBoundary

func (df DiyFp) NormalizeBoundary() DiyFp

func (DiyFp) NormalizedBoundaries

func (df DiyFp) NormalizedBoundaries() (DiyFp, DiyFp)

func (DiyFp) ToDouble

func (df DiyFp) ToDouble() float64

type Double

type Double struct {
	// contains filtered or unexported fields
}

func NewDouble

func NewDouble(d float64) Double

func NewDoubleUint64

func NewDoubleUint64(u uint64) Double

func (Double) EffectiveSignificandSize

func (d Double) EffectiveSignificandSize(order int) int

func (Double) Exponent

func (d Double) Exponent() int

func (Double) IntegerExponent

func (d Double) IntegerExponent() int

func (Double) IntegerSignificand

func (d Double) IntegerSignificand() uint64

func (Double) IsInf

func (d Double) IsInf() bool

func (Double) IsNan

func (d Double) IsNan() bool

func (Double) IsNanOrInf

func (d Double) IsNanOrInf() bool

func (Double) IsNormal

func (d Double) IsNormal() bool

func (Double) IsZero

func (d Double) IsZero() bool

func (Double) NextPositiveDouble

func (d Double) NextPositiveDouble() float64

func (Double) Sign

func (d Double) Sign() bool

func (Double) Significand

func (d Double) Significand() uint64

func (Double) ToBias

func (d Double) ToBias() uint64

func (Double) Uint64Value

func (d Double) Uint64Value() uint64

func (Double) Value

func (d Double) Value() float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL