From c8f904b7f5f53482293815822cebe7d5ac4247c1 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sun, 6 Jan 2019 23:05:13 +0900 Subject: Fix 0.0 and -0.0 handling. Fix the following issue: Good: $ bin/mruby -e 'p(-0.0)' #=> "-0" Bad: $ bin/mruby -e 'a=0.0; p(-0.0)' #=> "0" --- mrbgems/mruby-compiler/core/codegen.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index b3659863b..a17272ba7 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -566,9 +567,12 @@ new_lit(codegen_scope *s, mrb_value val) #ifndef MRB_WITHOUT_FLOAT case MRB_TT_FLOAT: for (i=0; iirep->plen; i++) { + mrb_float f1, f2; pv = &s->irep->pool[i]; if (mrb_type(*pv) != MRB_TT_FLOAT) continue; - if (mrb_float(*pv) == mrb_float(val)) return i; + f1 = mrb_float(*pv); + f2 = mrb_float(val); + if (f1 == f2 && !signbit(f1) == !signbit(f2)) return i; } break; #endif -- cgit v1.2.3