c - 为什么 printf 将整数打印为双精度数?
问题描述
printf("%f", 1.0); //prints 1.0
但
printf("%f", 1); // prints 0.0
转换是如何发生的?
解决方案
根据以下@Eric Postpischil's
评论不同。
The first double argument (or float argument, which will be promoted to double if used with the ... part of a function) is put in %xmm0. The first “normal integer class” type of argument would go into %rdi. For printf, though, that pointer to the format string is the first argument of that class, so it does into %rdi. That means the first int argument passed goes into the second register for that class, which is %rsi. So, with printf("%f", 1);, printf looks for the floating-point value in %xmm0, but the caller puts an int 1 in %rsi
推荐阅读
- r - 考虑另一列中的变量,查找同一列中的不匹配
- python - 没有熊猫的排序字典
- javascript - 如何在 AG Grid Vue 中刷新固定的行数据
- android - 尝试调用虚拟方法 'void com.android.server.wm.DisplayContent.moveStack(com.android.server.wm.TaskStack, boolean)'
- angular - 带有 AWS Lambda Angular 8 的 HttpInterceptor
- amazon-web-services - 如何为 Lambda 通过 API 调用创建的 ECS 服务构建 CI CD 管道
- xamarin - 如何更改 Rg.Plugins 弹出模板以用 C# 编码
- java - 将 .csv 文件数据导入显示不完整信息的 java 表
- java - Android画布添加描边和高程
- java - IntelliJ Kotlin - 如何在项目中修复“确保您依赖 Kotlin 标准库”?