Docs.rs
  • lexical-write-float-0.8.3
    • lexical-write-float 0.8.3
    • Docs.rs crate page
    • MIT/Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • Alexhuszagh
    • Dependencies
      • lexical-util ^0.8.3 normal
      • lexical-write-integer ^0.8.3 normal
      • static_assertions ^1 normal
      • approx ^0.5.0 dev
      • fraction ^0.8.0 dev
      • proptest ^0.10.1 dev
    • Versions
    • 99.28% of the crate is documented
  • Go to latest version
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation
logo

Crate lexical_write_float

logo

Crate lexical_write_float

  • Version 0.8.3
  • All Items
  • Modules
  • Structs
  • Enums
  • Constants
  • Traits

Modules

  • format
  • options

Structs

  • NumberFormatBuilder
  • Options
  • OptionsBuilder

Enums

  • RoundMode

Constants

  • BUFFER_SIZE

Traits

  • FormattedSize
  • ToLexical
  • ToLexicalWithOptions
  • WriteOptions
logo
Change settings

Crate lexical_write_float

source · [−]
Expand description

Fast and compact float-to-string conversions.

Features

Each float formatter contains extensive formatting control, including a maximum number of significant digits written, a minimum number of significant digits remaining, the positive and negative exponent break points (at what exponent, in scientific-notation, to force scientific notation), whether to force or disable scientific notation, and the rounding mode for truncated float strings.

Algorithms

There’s currently 5 algorithms used, depending on the requirements.

  1. Compact for decimal strings uses the Grisu algorithm.
  2. An optimized algorithm based on the Dragonbox algorithm.
  3. An optimized algorithm for formatting to string with power-of-two radixes.
  4. An optimized algorithm for hexadecimal floats.
  5. A fallback algorithm for all other radixes.

The Grisu algorithm is based on “Printing Floating-Point Numbers Quickly and Accurately with Integers”, by Florian Loitsch, available online here. The dragonbox algorithm is based on the reference C++ implementation, hosted here, and the algorithm is described in depth here. The radix algorithm is adapted from the V8 codebase, and may be found here.

Features

  • std - Use the standard library.
  • power-of-two - Add support for wring power-of-two float strings.
  • radix - Add support for strings of any radix.
  • compact - Reduce code size at the cost of performance.
  • safe - Ensure only memory-safe indexing is used.

Note

Only documented functionality is considered part of the public API: any of the modules, internal functions, or structs may change release-to-release without major or minor version changes. Use internal implementation details at your own risk.

lexical-write-float mainly exists as an implementation detail for lexical-core, although its API is stable. If you would like to use a high-level API that writes to and parses from String and &str, respectively, please look at lexical instead. If you would like an API that supports multiple numeric conversions, please look at lexical-core instead.

Version Support

The minimum, standard, required version is 1.51.0, for const generic support. Older versions of lexical support older Rust versions.

Design

  • Algorithm Approach
  • Benchmarks

Modules

format

Public API for the number format packed struct.

options

Configuration options for writing floats.

Structs

NumberFormatBuilder

Build number format from specifications.

Options

Options to customize writing floats.

OptionsBuilder

Builder for Options.

Enums

RoundMode

Enumeration for how to round floats with precision control.

Constants

BUFFER_SIZE

Maximum number of bytes required to serialize any number to string.

Traits

FormattedSize

The size, in bytes, of formatted values.

ToLexical

Trait for numerical types that can be serialized to bytes.

ToLexicalWithOptions

Trait for numerical types that can be serialized to bytes with custom options.

WriteOptions

Shared trait for all writer options.

Loading search results...