+ (CGFloat) Math_max:(id)firstObject, ...;
{
id eachObject;
va_list argumentList;
CGFloat max = [firstObject floatValue];
if (firstObject)
{
va_start(argumentList, firstObject); // Start scanning for arguments after firstObject.
eachObject = va_arg(argumentList, id);
while (eachObject) // As many times as we can get an argument of type "id"
{
if ([eachObject floatValue]>max) {
max = [eachObject floatValue];
}
eachObject = va_arg(argumentList, id);
}
va_end(argumentList);
}
return max;
}
+ (CGFloat) Math_min:(id)firstObject, ...;
{
id eachObject;
va_list argumentList;
CGFloat min = [firstObject floatValue];
if (firstObject)
{
va_start(argumentList, firstObject); // Start scanning for arguments after firstObject.
eachObject = va_arg(argumentList, id);
while (eachObject) // As many times as we can get an argument of type "id"
{
if ([eachObject floatValue]<min) {
min = [eachObject floatValue];
}
eachObject = va_arg(argumentList, id);
}
va_end(argumentList);
}
return min;
}
用法
maxHighPrice = [NPUtils Math_max:[NSNumber numberWithFloat:maxHighPrice],
[kline objectAtIndex:2],
[arrayMainIndicator objectAtIndex:1],
[arrayMainIndicator objectAtIndex:2],
[arrayMainIndicator objectAtIndex:3],
[arrayMainIndicator objectAtIndex:4],
nil];