#floating-point #numeric #macro #plugin

nightly hexfloat

Syntax extension to create floating point literals from hexadecimal strings

7 releases

Uses old Rust 2015

0.1.3 Mar 8, 2015
0.1.2 Jan 9, 2015
0.0.4 Jan 9, 2015
0.0.3 Nov 27, 2014

#98 in #floating-point

MIT/Apache

8KB
125 lines

hexfloat

A Rust syntax extension to create floating point literals from hexadecimal strings.

Usage

Add this to your Cargo.toml:

[dependencies]

hexfloat = "*"

and this to your crate root:

#![feature(phase)]
#[phase(plugin)]
extern crate hexfloat;

lib.rs:

Syntax extension to create floating point literals from hexadecimal strings

Once loaded, hexfloat!() is called with a string containing the hexadecimal floating-point literal, and an optional type (f32 or f64). If the type is omitted, the literal is treated the same as a normal unsuffixed literal.

Examples

To load the extension and use it:

#[phase(plugin)]
extern crate hexfloat;

fn main() {
    let val = hexfloat!("0x1.ffffb4", f32);
}

References

No runtime deps