当CGPointMake遇到大数字时 [英] When CGPointMake meets big number
本文介绍了当CGPointMake遇到大数字时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作基于时间的绘图。例如:定义一个点供以后使用。
I am trying to make a time based drawing. For example: define a point for later use.
CGPoint testPoint = CGPointMake(2341.2345, 1350046324.1234);
然后testPoint.y变为1350046336.00,这不是我们放在那里。
我正在使用Xcode 4.5。
有什么想法吗?谢谢。
Then testPoint.y becomes 1350046336.00 which is not we put there. I am using Xcode 4.5. Any ideas? Thanks.
推荐答案
CGPoint使用float(32bit)数据类型(至少在iOS6上)。
CGPoint uses float (32bit) datatypes (at least on iOS6).
从标题中:
CGPointMake(CGFloat x, CGFloat y) ...
with
typedef CGFLOAT_TYPE CGFloat;
和
# define CGFLOAT_TYPE float
所以这导致我的测试代码:
So this results in my test code:
CGPoint testPoint1 = CGPointMake(2341.2345, 1350046324.1234);
CGPoint testPoint2 = CGPointMake(2341.2345f, 1350046324.1234f);
double d = 1350046324.1234;
float f = 1350046324.1234;
NSLog(@"%f %f %f %f", testPoint1.y, testPoint2.y, d, f);
打印到日志:
1350046336.000000 1350046336.000000 1350046324.123400 1350046336.000000
所以你只剩下数字范围单精度浮子就足够了。
多数民众赞成。
So you just left the range of numbers where single precision floats are good enough. Thats all.
BTW。:在我偶然发现你的问题之前,我确实认为CGFloat是双倍的。
BTW.: I did think CGFloat is double before I stumbled upon your question.
这篇关于当CGPointMake遇到大数字时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文