#floating-point #packet #f64 #f32

bin+lib ieee-754

A library to convert a hexadecimal value to a 32-bit or 64-bit floating-point precision following the IEEE 754 standard

2 releases

0.1.4 Feb 22, 2025
0.1.3 Feb 8, 2025
0.1.2 Feb 8, 2025
0.1.1 Feb 7, 2025
0.1.0 Feb 5, 2025

#370 in Value formatting

Download history 324/week @ 2025-02-05 17/week @ 2025-02-12 135/week @ 2025-02-19 22/week @ 2025-02-26 2/week @ 2025-03-05 6/week @ 2025-03-12

168 downloads per month

MIT license

34KB
739 lines

IEEE 754 Floating-Point Representation

The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation which was established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE).

To learn more about IEEE754 kindly visit: https://www.geeksforgeeks.org/ieee-standard-754-floating-point-numbers/

Example 1:

Converting a hexadecimal to 64-bit floating-point value using IEEE754 double precision.

use crate::ieee754::IEEE754;

let values = vec![0xc0, 0x52, 0xaf, 0xbe, 0x4, 0x89, 0x76, 0x8e];
let test: IEEE754 = IEEE754::to_64bit_float(values.clone());
println!("Input: {:x?}", values);
println!("Expected Output: {}", -74.74597276138431);
assert_eq!(-74.74597276138431, test);

Example 2:

Converting a hexadecimal to 32-bit floating-point value using IEEE754 single precision.

use crate::ieee754::IEEE754;

let values = vec![0x00, 0x00, 0x00, 0x00];
let test: f32= IEEE754::to_32bit_float(values.clone()).unwrap();
println!("Input: {:x?}", values);
println!("Expected Output: {}", 0.0);
assert_eq!(0.0, test);

Example 3:

Converting a 32-bit floating point to hexadecimal value using IEEE754 single precision.

use crate::ieee754::IEEE754;

let values = -33.33333333;
let output = IEEE754::to_32bit_hex(values.clone());
println!("Input: {:x?}", values);
println!("Expected Output: C2055555");
assert_eq!(output.unwrap(), "C2055555");

Example 4:

Converting a 64-bit floating point to hexadecimal value using IEEE754 double precision.

use crate::ieee754::IEEE754;

let values = -33.33333333;
let output = IEEE754::to_64bit_hex(values.clone());
println!("Input: {:x?}", values);
println!("Expected Output: C040AAAAAAA38226");
assert_eq!(output.unwrap(), "C040AAAAAAA38226");

References:

No runtime deps