c - 带后缀“f”的双常量用法
问题描述
double f_64 = 3.35f;
double f1_64 = 3.35;
如果使用后缀“f”有什么影响?
使用在线 FPU 编译器,十六进制结果如下
带后缀f
- 0x400ACCCCC0000000
,
不带后缀f
- 0x400ACCCCCCCCCCCD
。
解决方案
f
后缀强制编译器将值与下面的赋值中的float
a 相反,double
这没有多大意义。
double f_64 = 3.35f;
// Why force a value to float when you've allocated memory for a double
请记住,这double
是2 倍的精度float
。根据您的具体需求选择类型。
但是,说,你在做
float ans;
ans = 3/2; // ans is trimmed to an int
ans = 3/2.0f; // The decimals are retained
推荐阅读
- html - 使 Div 垂直填充其父级
- keras - Keras 中的双向层:不支持的操作数类型
- android - 如何启用 Webview 视频下载按钮?
- python-3.x - fmin_tnc 的渐变不起作用
- android - 未从 youtube 数据 api 获得响应
- django - 在提供文件 nginx django 时使用 UUID 缩短 URL
- css - 用 vw 单位减去像素量定义的网格列?
- c# - 将 base64string 中保存的数据的编码更改为 UTF8
- list - Cypher:从节点列表中获取相关节点列表
- html - Firefox 中绝对定位的元素内部链接的问题