您的位置:首页 > 其它

double 类型的有效位

2017-07-04 11:37 495 查看
// double has 53 bit significant, therefore 2^53=9007199254740992
// is the largest integer that can be represented. For a floating
// point value, that consumes more than 16 characters may result
// in precision loss during conversion. Note that we are being
// pessimistic in that some floating point values that consume
// 17 characters may be represented without conversion loss.
if ( json->cfg->decode_big_numbers_as_strings &&
( endptr - json->ptr > 16 ||
fabs(token->value.number) > 9007199254740991.0 ) )
{
token->type = T_STRING;
strbuf_reset(json->tmp);
for (; json->ptr != endptr; json->ptr++ ) {
strbuf_append_char_unsafe(json->tmp, json->ptr[0]);
}
token->value.string = strbuf_string(json->tmp, &token->string_len);
return;
}

double类型有效位是16位,

当用double类型表示的数超过16位时,为了输出正确的值,可以转换为string类型输出
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: