diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-02-16 14:42:01 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2015-02-16 14:42:01 +0900 |
| commit | a88a20d51f5877b231877261d29fee9d66a20214 (patch) | |
| tree | e3b993e905b6afa11c6c1ccd0feb3741e4db13fb /src/dump.c | |
| parent | 1fa081a6468f830fc9fe20c7215a9655eceabc61 (diff) | |
| parent | 6f893b5183450384e89b3d8f03f9ef32a7522624 (diff) | |
| download | mruby-a88a20d51f5877b231877261d29fee9d66a20214.tar.gz mruby-a88a20d51f5877b231877261d29fee9d66a20214.zip | |
Merge pull request #2723 from cremno/use-musl-fmt_fp
re-implement mrb_float_to_str()
Diffstat (limited to 'src/dump.c')
| -rw-r--r-- | src/dump.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/dump.c b/src/dump.c index 24ddd90b8..3113a71d3 100644 --- a/src/dump.c +++ b/src/dump.c @@ -18,6 +18,12 @@ #ifdef ENABLE_STDIO +#ifdef MRB_USE_FLOAT +#define MRB_FLOAT_FMT "%.9e" +#else +#define MRB_FLOAT_FMT "%.16e" +#endif + static size_t get_irep_record_size_1(mrb_state *mrb, mrb_irep *irep); #if UINT32_MAX > SIZE_MAX @@ -111,7 +117,6 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep) size_t size = 0; size_t pool_no; mrb_value str; - char buf[32]; size += sizeof(uint32_t); /* plen */ size += irep->plen * (sizeof(uint8_t) + sizeof(uint16_t)); /* len(n) */ @@ -130,9 +135,9 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep) break; case MRB_TT_FLOAT: + str = mrb_float_to_str(mrb, irep->pool[pool_no], MRB_FLOAT_FMT); { - int len; - len = mrb_float_to_str(buf, mrb_float(irep->pool[pool_no])); + mrb_int len = RSTRING_LEN(str); mrb_assert_int_fit(mrb_int, len, size_t, SIZE_MAX); size += (size_t)len; } @@ -163,7 +168,6 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) uint16_t len; mrb_value str; const char *char_ptr; - char char_buf[30]; cur += uint32_to_bin(irep->plen, cur); /* number of pool */ @@ -186,13 +190,15 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf) case MRB_TT_FLOAT: cur += uint8_to_bin(IREP_TT_FLOAT, cur); /* data type */ + str = mrb_float_to_str(mrb, irep->pool[pool_no], MRB_FLOAT_FMT); + char_ptr = RSTRING_PTR(str); { - int tlen; - tlen = mrb_float_to_str(char_buf, mrb_float(irep->pool[pool_no])); - mrb_assert_int_fit(int, tlen, uint16_t, UINT16_MAX); + mrb_int tlen; + + tlen = RSTRING_LEN(str); + mrb_assert_int_fit(mrb_int, tlen, uint16_t, UINT16_MAX); len = (uint16_t)tlen; } - char_ptr = &char_buf[0]; break; case MRB_TT_STRING: |
