对于假定的浮点值或双精度值,写0.0,0.0f或.0f而不是简单0是否更好? [英] Is it better to write 0.0, 0.0f or .0f instead of simple 0 for supposed float or double values

查看:797
本文介绍了对于假定的浮点值或双精度值,写0.0,0.0f或.0f而不是简单0是否更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,所有人都在标题中。该问题尤其适用于所有那些可能类似于 NSTimeInterval CGFloat 或浮动或其他任何变量的值一双。谢谢。

Hello well all is in the title. The question apply especially for all those values that can be like NSTimeInterval, CGFloat or any other variable that is a float or a double. Thanks.

编辑:我要求的是值分配而不是格式化字符串。

I'm asking for value assignment not format in a string.

编辑2:问题是确实为浮点数分配了一个普通的 0 ,或者一个双重比任何一个 f 的结果更糟糕了。

EDIT 2: The question is really does assigning a plain 0 for a float or a double is worst than anything with f a the end.

推荐答案

基本区别如下:

1.0 1. 是双常数

1.0f 是一个浮点常量

如果没有后缀,其中带有小数的文字(123.0)将被视为double -precision浮点数。如果将其分配或传递给单精度变量或参数,编译器将(应该)发出警告。附加 f 告诉编译器您希望将文字视为单精度浮点数。

Without a suffix, a literal with a decimal in it (123.0) will be treated as a double-precision floating-point number. If you assign or pass that to a single-precision variable or parameter, the compiler will (should) issue a warning. Appending f tells the compiler you want the literal to be treated as a single-precision floating-point number.

这篇关于对于假定的浮点值或双精度值,写0.0,0.0f或.0f而不是简单0是否更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆