我的 iOS 应用程序有时会在尝试查找 GCF 时崩溃。它不会一直发生。只有某些时候。
这是 GCF 函数:
+(NSNumber *)getGCFOf: (NSNumber *)frstNumber and: (NSNumber *)scndNumber {
float t, r;
//Convert input to floats
float frstNumberFloat = frstNumber.floatValue; //EXC_BAD_ACESS(code=2 address=0xbf7fffdc)
float scndNumberFloat = scndNumber.floatValue;
if (frstNumberFloat < scndNumberFloat){
t = frstNumberFloat;
frstNumberFloat = scndNumberFloat;
scndNumberFloat = t;
}
r = fmodf(frstNumberFloat, scndNumberFloat);
if (r == 0) {
NSNumber *scndNumberNS = [NSNumber numberWithFloat:scndNumberFloat];
return scndNumberNS;
}
else {
NSNumber *inputOne = [NSNumber numberWithFloat: scndNumberFloat];
NSNumber *inputTwo = [NSNumber numberWithFloat: r];
return [Fractions getGCFOf: inputOne and: inputTwo];
}
}