当我试图为一个double变量分配一个大的数字时,我会收到以下警告
sqrt.c:8:11:警告:整数常数对其类型来说太大了 双x=28462391747582051264412870770688;
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <float.h>
int main() {
printf("MAX_DBL=%.53f\n",DBL_MAX);
double x=28462391747582051264412870770688;
}然而,MAX_DBL比我试图分配的数字要大。
发布于 2017-11-07 00:45:22
double x=28462391747582051264412870770688;数字文字的类型不是double,而是int。这个数字对于int来说太大了。
如果使用double文字:
double x=28462391747582051264412870770688.0;警告消失,但如果需要,该数字将舍入到下一个可表示的double。(这里的这个特定数字是可表示的,as @chux noticed。)
https://stackoverflow.com/questions/47148130
复制相似问题