Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WVito opened this issue Oct 31, 2024 · 1 comment
Open

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

WVito opened this issue Oct 31, 2024 · 1 comment

Comments

@WVito
Copy link

WVito commented Oct 31, 2024

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
Copy link
Owner

Bwar commented Nov 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants