Crate radix_ecmascript

source ·
Expand description

radix-ecmascript adds a function, to_radix_str, to floating-point types (f32 and f64) to allow callers to obtain their radix string representation, just like in JavaScript, in pure Rust. This library has no dependencies and is very lightweight.

This library implements ECMAScript Language Specification Section 9.8.1, “ToString Applied to the Number Type”, and uses the same logic as found in Google’s open-source V8 engine.

DoubleToRadixCString Double utility

Example:

use radix_ecmascript::ToRadixStr;

println!("{}", (0.123).to_radix_str(16).unwrap());

This code prints 0.1f7ced916872b, which can also be achieved by running (0.123).toString(16) in JavaScript.

This code unwraps the returned Result, but you should (probably) handle the error in real cases. to_radix_str will only return InvalidBaseError if the given Base is outside of the valid range, MIN_BASE and MAX_BASE.

Structs

Constants

Traits

  • Allows a type to be converted to radix string representation.

Type Definitions

  • A floating-point base.