ToHex

Trait ToHex 

Source
pub trait ToHex {
    // Required method
    fn to_hex(self) -> String;
}
Expand description

ToHex is a trait that provides a method for converting floating-point numbers to their hexadecimal representation.

This trait is implemented for f32 and f64 types.

§Examples

use fhex::ToHex;

let num: f32 = 1.23;
let hex = num.to_hex();
println!("{}", hex);

This will print the hexadecimal representation of 1.23.

Required Methods§

Source

fn to_hex(self) -> String

Converts the floating-point number to a hexadecimal string of the format ±0xh.hhhp±d.

The returned string starts with “0x” for positive numbers and “-0x” for negative numbers. The string uses lowercase letters for the hexadecimal digits ‘a’ to ‘f’. The exponent is represented by ‘p’, as specified in the IEEE 754 standard. NaN and Infinity and -Infinity are represented by “nan”, “inf” and “-inf” respectively. Signalling NaN is represented by “nan:0x” followed by the significand in hexadecimal.

§Examples
use fhex::ToHex;

let num: f32 = 1.23;
assert_eq!(num.to_hex(), "0x1.3ae148p+0");

Implementations on Foreign Types§

Source§

impl ToHex for f32

Source§

impl ToHex for f64

Implementors§