diff --git a/src/obj_numeric.c b/src/obj_numeric.c index 6a9997d..ad4f7fa 100644 --- a/src/obj_numeric.c +++ b/src/obj_numeric.c @@ -62,7 +62,10 @@ KRK_METHOD(float,__float__,{ return argv[0]; }) KRK_METHOD(float,__str__,{ char tmp[100]; - size_t l = snprintf(tmp, 100, "%g", self); + size_t l = snprintf(tmp, 97, "%.16g", self); + if (!strstr(tmp,".") && !strstr(tmp,"e")) { + l = snprintf(tmp,100,"%.16g.0",self); + } return OBJECT_VAL(krk_copyString(tmp, l)); }) diff --git a/src/value.c b/src/value.c index 4fd0288..8f31e08 100644 --- a/src/value.c +++ b/src/value.c @@ -28,33 +28,6 @@ void krk_freeValueArray(KrkValueArray * array) { } void krk_printValue(FILE * f, KrkValue printable) { - if (!IS_OBJECT(printable)) { - switch (printable.type) { - case VAL_INTEGER: fprintf(f, PRIkrk_int, AS_INTEGER(printable)); break; - case VAL_BOOLEAN: fprintf(f, "%s", AS_BOOLEAN(printable) ? "True" : "False"); break; - case VAL_FLOATING: fprintf(f, "%g", AS_FLOATING(printable)); break; - case VAL_NONE: fprintf(f, "None"); break; - case VAL_HANDLER: fprintf(f, "{%s->%d}", AS_HANDLER(printable).type == OP_PUSH_TRY ? "try" : "with", (int)AS_HANDLER(printable).target); break; - case VAL_KWARGS: { - if (AS_INTEGER(printable) == LONG_MAX) { - fprintf(f, "{unpack single}"); - } else if (AS_INTEGER(printable) == LONG_MAX-1) { - fprintf(f, "{unpack list}"); - } else if (AS_INTEGER(printable) == LONG_MAX-2) { - fprintf(f, "{unpack dict}"); - } else if (AS_INTEGER(printable) == LONG_MAX-3) { - fprintf(f, "{unpack nil}"); - } else if (AS_INTEGER(printable) == 0) { - fprintf(f, "{unset default}"); - } else { - fprintf(f, "{sentinel=" PRIkrk_int "}",AS_INTEGER(printable)); - } - break; - } - default: break; - } - return; - } KrkClass * type = krk_getType(printable); if (type->_tostr) { krk_push(printable); @@ -75,7 +48,30 @@ void krk_printValue(FILE * f, KrkValue printable) { void krk_printValueSafe(FILE * f, KrkValue printable) { if (!IS_OBJECT(printable)) { - krk_printValue(f,printable); + switch (printable.type) { + case VAL_INTEGER: fprintf(f, PRIkrk_int, AS_INTEGER(printable)); break; + case VAL_BOOLEAN: fprintf(f, "%s", AS_BOOLEAN(printable) ? "True" : "False"); break; + case VAL_FLOATING: fprintf(f, "%.16g", AS_FLOATING(printable)); break; + case VAL_NONE: fprintf(f, "None"); break; + case VAL_HANDLER: fprintf(f, "{%s->%d}", AS_HANDLER(printable).type == OP_PUSH_TRY ? "try" : "with", (int)AS_HANDLER(printable).target); break; + case VAL_KWARGS: { + if (AS_INTEGER(printable) == LONG_MAX) { + fprintf(f, "{unpack single}"); + } else if (AS_INTEGER(printable) == LONG_MAX-1) { + fprintf(f, "{unpack list}"); + } else if (AS_INTEGER(printable) == LONG_MAX-2) { + fprintf(f, "{unpack dict}"); + } else if (AS_INTEGER(printable) == LONG_MAX-3) { + fprintf(f, "{unpack nil}"); + } else if (AS_INTEGER(printable) == 0) { + fprintf(f, "{unset default}"); + } else { + fprintf(f, "{sentinel=" PRIkrk_int "}",AS_INTEGER(printable)); + } + break; + } + default: break; + } } else if (IS_STRING(printable)) { fprintf(f, "'"); /* diff --git a/test/testOperators.krk.expect b/test/testOperators.krk.expect index 0e7240f..9aea8ca 100644 --- a/test/testOperators.krk.expect +++ b/test/testOperators.krk.expect @@ -1,5 +1,5 @@ -1.90665 -1.90665 +1.906645911848772 +1.906645911848772 246 246 123