1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#![no_std]
#![doc(html_root_url = "https://docs.rs/ryu-floating-decimal/1.0.4")]
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
#![cfg_attr(
feature = "cargo-clippy",
allow(cast_lossless, many_single_char_names, unreadable_literal,)
)]
#[cfg(feature = "no-panic")]
extern crate no_panic;
mod common;
mod d2s;
#[cfg(not(feature = "small"))]
mod d2s_full_table;
mod d2s_intrinsics;
#[cfg(feature = "small")]
mod d2s_small_table;
mod f2s;
#[cfg(feature = "no-panic")]
use no_panic::no_panic;
pub use d2s::FloatingDecimal64;
use core::mem;
#[cfg_attr(feature = "no-panic", inline)]
#[cfg_attr(feature = "no-panic", no_panic)]
pub fn d2d(val: f64) -> FloatingDecimal64 {
let bits: u64 = unsafe { mem::transmute(val) };
let ieee_mantissa = bits & ((1u64 << d2s::DOUBLE_MANTISSA_BITS) - 1);
let ieee_exponent =
(bits >> d2s::DOUBLE_MANTISSA_BITS) as u32 & ((1u32 << d2s::DOUBLE_EXPONENT_BITS) - 1);
d2s::d2d(ieee_mantissa, ieee_exponent)
}
pub use f2s::FloatingDecimal32;
#[cfg_attr(feature = "no-panic", inline)]
#[cfg_attr(feature = "no-panic", no_panic)]
pub fn f2d(val: f32) -> FloatingDecimal32 {
let bits: u32 = unsafe { mem::transmute(val) };
let ieee_mantissa = bits & ((1u32 << f2s::FLOAT_MANTISSA_BITS) - 1);
let ieee_exponent =
(bits >> f2s::FLOAT_MANTISSA_BITS) as u32 & ((1u32 << f2s::FLOAT_EXPONENT_BITS) - 1);
f2s::f2d(ieee_mantissa, ieee_exponent)
}