Commit c8f904b7 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

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"
parent 89c79e56
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <mruby.h> #include <mruby.h>
#include <mruby/compile.h> #include <mruby/compile.h>
#include <mruby/proc.h> #include <mruby/proc.h>
...@@ -566,9 +567,12 @@ new_lit(codegen_scope *s, mrb_value val) ...@@ -566,9 +567,12 @@ new_lit(codegen_scope *s, mrb_value val)
#ifndef MRB_WITHOUT_FLOAT #ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT: case MRB_TT_FLOAT:
for (i=0; i<s->irep->plen; i++) { for (i=0; i<s->irep->plen; i++) {
mrb_float f1, f2;
pv = &s->irep->pool[i]; pv = &s->irep->pool[i];
if (mrb_type(*pv) != MRB_TT_FLOAT) continue; 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; break;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment