1 | use crate::digit_table::*; |
2 | use core::ptr; |
3 | |
4 | #[cfg_attr (feature = "no-panic" , inline)] |
5 | pub unsafe fn write_exponent3(mut k: isize, mut result: *mut u8) -> usize { |
6 | let sign: bool = k < 0; |
7 | if sign { |
8 | *result = b'-' ; |
9 | result = result.offset(count:1); |
10 | k = -k; |
11 | } |
12 | |
13 | debug_assert!(k < 1000); |
14 | if k >= 100 { |
15 | *result = b'0' + (k / 100) as u8; |
16 | k %= 100; |
17 | let d: *const u8 = DIGIT_TABLE.as_ptr().offset(count:k * 2); |
18 | ptr::copy_nonoverlapping(src:d, dst:result.offset(1), count:2); |
19 | sign as usize + 3 |
20 | } else if k >= 10 { |
21 | let d: *const u8 = DIGIT_TABLE.as_ptr().offset(count:k * 2); |
22 | ptr::copy_nonoverlapping(src:d, dst:result, count:2); |
23 | sign as usize + 2 |
24 | } else { |
25 | *result = b'0' + k as u8; |
26 | sign as usize + 1 |
27 | } |
28 | } |
29 | |
30 | #[cfg_attr (feature = "no-panic" , inline)] |
31 | pub unsafe fn write_exponent2(mut k: isize, mut result: *mut u8) -> usize { |
32 | let sign: bool = k < 0; |
33 | if sign { |
34 | *result = b'-' ; |
35 | result = result.offset(count:1); |
36 | k = -k; |
37 | } |
38 | |
39 | debug_assert!(k < 100); |
40 | if k >= 10 { |
41 | let d: *const u8 = DIGIT_TABLE.as_ptr().offset(count:k * 2); |
42 | ptr::copy_nonoverlapping(src:d, dst:result, count:2); |
43 | sign as usize + 2 |
44 | } else { |
45 | *result = b'0' + k as u8; |
46 | sign as usize + 1 |
47 | } |
48 | } |
49 | |