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