|
7 | 7 | #include "py/mpz.h"
|
8 | 8 | #include "py/builtin.h"
|
9 | 9 | #include "py/emit.h"
|
| 10 | +#include "py/formatfloat.h" |
10 | 11 |
|
11 | 12 | #if defined(MICROPY_UNIX_COVERAGE)
|
12 | 13 |
|
@@ -136,6 +137,26 @@ STATIC mp_obj_t extra_coverage(void) {
|
136 | 137 | mp_emitter_warning(MP_PASS_CODE_SIZE, "test");
|
137 | 138 | }
|
138 | 139 |
|
| 140 | + // format float |
| 141 | + { |
| 142 | + mp_printf(&mp_plat_print, "# format float\n"); |
| 143 | + |
| 144 | + // format with inadequate buffer size |
| 145 | + char buf[5]; |
| 146 | + mp_format_float(1, buf, sizeof(buf), 'g', 0, '+'); |
| 147 | + mp_printf(&mp_plat_print, "%s\n", buf); |
| 148 | + |
| 149 | + // format with just enough buffer so that precision must be |
| 150 | + // set from 0 to 1 twice |
| 151 | + char buf2[8]; |
| 152 | + mp_format_float(1, buf2, sizeof(buf2), 'g', 0, '+'); |
| 153 | + mp_printf(&mp_plat_print, "%s\n", buf2); |
| 154 | + |
| 155 | + // format where precision is trimmed to avoid buffer overflow |
| 156 | + mp_format_float(1, buf2, sizeof(buf2), 'e', 0, '+'); |
| 157 | + mp_printf(&mp_plat_print, "%s\n", buf2); |
| 158 | + } |
| 159 | + |
139 | 160 | // return a tuple of data for testing on the Python side
|
140 | 161 | mp_obj_t items[] = {(mp_obj_t)&str_no_hash_obj, (mp_obj_t)&bytes_no_hash_obj};
|
141 | 162 | return mp_obj_new_tuple(MP_ARRAY_SIZE(items), items);
|
|
0 commit comments