小编Nan*_*ish的帖子

是否可以在不损失64位计算机精度的情况下为int64_t分配long long returne值?

我已经实现了以下代码:

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<cstdlib>
#include<sys/types.h>
main()
{
    int64_t i64value1 = 0;
    int64_t i64value2 = 0;
    long long llvalue = 0;
    const char *s = "10811535359";
    i64value1 = atoll(s);
    llvalue = atoll(s);
    i64value2 = llvalue;
    printf("s : [%s]\n",s);
    printf("i64value1 : [%d]\n",i64value1);
    printf("llvalue : [%lld]\n",llvalue);
    printf("i64value2 : [%d]\n",i64value2);
}
Run Code Online (Sandbox Code Playgroud)

上述进展的输出是:

s : [10811535359]
i64value1 : [-2073366529]
llvalue : [10811535359]
i64value2 : [-2073366529]
Run Code Online (Sandbox Code Playgroud)

使用的编译器是:

 gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)
Run Code Online (Sandbox Code Playgroud)

操作系统是x86_64 GNU/Linux 2.6.18-194

由于long long是带符号的64位整数,并且对于所有意图和目的,与int64_t类型相同,逻辑上int64_t …

c c++

0
推荐指数
1
解决办法
355
查看次数

标签 统计

c ×1

c++ ×1