Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
fpfmt package - rsc.io/fpfmt - Go Packages
[go: Go Back, main page]

fpfmt

package module
v0.0.0-...-0a37c4b Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package fpfmt implements floating point formatting algorithm and benchmarks to compare with other algorithms.

Example (Div)

Output:

⟨2.5+⟩ 3
Example (Nudge)

Output:

x        nudge(-1).floor  floor  ceil  nudge(+1).ceil
⟨15.0⟩   14               15     15    16
⟨15.0+⟩  15               15     16    16
⟨15.5+⟩  15               15     16    16
⟨16.0⟩   15               16     16    17
Example (Unround)

Output:

x      raw  str
6      24   ⟨6.0⟩
6.001  25   ⟨6.0+⟩
6.499  25   ⟨6.0+⟩
6.5    26   ⟨6.5⟩
6.501  27   ⟨6.5+⟩
6.999  27   ⟨6.5+⟩
7      28   ⟨7.0⟩
Example (Unround_floor)

Output:

x       floor  round½↓  round  round½↑  ceil
⟨6.0⟩   6      6        6      6        6
⟨6.0+⟩  6      6        6      6        7
⟨6.0+⟩  6      6        6      6        7
⟨6.5⟩   6      6        6      7        7
⟨6.5+⟩  6      7        7      7        7
⟨6.5+⟩  6      7        7      7        7
⟨7.0⟩   7      7        7      7        7
⟨7.5⟩   7      7        8      8        8
⟨8.5⟩   8      8        8      9        9

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Digits

func Digits(d uint64) int

Digits returns the number of decimal digits in d.

func FixedWidth

func FixedWidth(f float64, n int) (d uint64, p int)

FixedWidth returns the n-digit decimal form of f as d * 10**p. n can be at most 18.

func Fmt

func Fmt(s []byte, d uint64, p, nd int) int

Fmt formats d, p into s in exponential notation. The caller must pass nd set to the number of digits in d. It returns the number of bytes written to s.

func Parse

func Parse(d uint64, p int) float64

Parse rounds d * 10**p to the nearest float64 f. d can have at most 19 digits.

func ParseText

func ParseText(s []byte) (f float64, ok bool)

ParseText parses a decimal string s and returns the nearest floating point value. It returns 0, false if the input s is malformed.

func Short

func Short(f float64) (d uint64, p int)

Short computes the shortest formatting of f, using as few digits as possible that will still round trip back to the original float64.

Types

This section is empty.

Directories

Path Synopsis
Package bench exists to provide a C library.
Package bench exists to provide a C library.
dmg
ryu
Package fpfmt implements floating point formatting algorithm and benchmarks to compare with other algorithms.
Package fpfmt implements floating point formatting algorithm and benchmarks to compare with other algorithms.

Jump to

Keyboard shortcuts

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