Bwar / CJsonObject

Ultralightweight JSON parser in C++ based on cJSON
MIT License
648 stars 239 forks source link

parse_number负double数值解析出来为正值 #66

Open WVito opened 3 weeks ago

WVito commented 3 weeks ago
if (scale == 0 && subscale == 0)
{
    item->valuedouble = item->sign * d;
    item->valueint = item->sign * n;
    item->type = cJSON_Int;
}
else
{
    printf("subscale = %d, signsubscale = %d, s = %.16f\n", subscale, signsubscale, d);
    if (subscale != 0)
    {
        d = item->sign * base * pow(10.0, (scale + subscale * signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
    }

    item->valuedouble = d;
    item->valueint = n;
    printf("d = %.16f, base = %.16f, valuedouble = %.16f\n", d, base, item->valuedouble);
    item->type = cJSON_Double;
}

经测试,负double值时,scale < 0, subscale == 0, item->sign < 0,d值并不会经过d * item->sign,因此解析出来的只会是正值。

Bwar commented 3 weeks ago

调用哪个函数获取值的时候负double会取到正值?
如果是 operator() 这个方法,两个月前已修复,更新一下最新代码即可。