iphone-common-codes-ccteam源代码 CCNSNumber.m

本文详细解读了CCNSNumber类中的关键方法,包括浮点数与零的比较、浮点数之间的比较、整型溢出检测、整型转字符串、角度转弧度等,并提供了代码实现与使用示例。
// // CCNSNumber.m // CCFC // // Created by xichen on 11-12-17. // Copyright 2011年 ccteam. All rights reserved. // #import "CCNSNumber.h" #import <math.h> @implementation NSNumber(cc) - (BOOL)floatEqualToZero { return FLOAT_EQUAL_TO_ZERO([self floatValue]); } - (BOOL)floatEqualToFloat:(NSNumber *)another { return FLOAT_EQUAL_TO_FLOAT([self floatValue], [another floatValue]); } // 判断两个整形加法是否溢出 + (int)addCheckOverflow:(int)a withB:(int)b overFlow:(int *)overFlowFlag { int sum = a + b; *overFlowFlag = 0; if(a > 0 && b > 0 && sum < 0 || a < 0 && b < 0 && sum > 0) { *overFlowFlag = 1; } return sum; } // 整型转换成字符串,返回转换后的字符串的实际长度 + (int)itoa:(char *)str maxLen:(const int)maxLen num:(int)n { char temp[32] = {0}; int i = 0; while(n) { if(i >= 32) { return -1; } temp[i++] = (n % 10) + '0'; // 将整型数的各位对应的字符值保存在数组中 n /= 10; } if(i > maxLen) // 长度过长,返回0 { return -1; } int len = i; int j = 0; while (i >= 0) { str[j++] = temp[--i]; // 拷贝到外部字符串中 } str[i] = '\0'; return len; } // 根据角度获取弧度值 + (double)getRadiusByDegrees:(double)degrees { return degrees * M_PI / 180; } @end


可能有更新:

googlecode链接地址:http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCNSNumber.m

github地址:https://github.com/cxsjabc/iphone-common-codes-ccteam/tree/master/CCFC/files/CCNSNumber.m


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值