nan 값 체크하기

2014. 10. 28. 17:49개발자료/iOS


반응형

MPMoviePlayerController의 currentPlaybackTime값을 가져와서 이어보기를 구현하는데 문제가 발생했다.

currentPlaybackTime값이 nan으로 나오는 것이다.

위치가 0인지 아니면 아예 값을 못가져오는 nan인지 체크하기 위해 아래의 함수를 사용한다.

 

if(isnan(x)){

  // 값이 nan 이다

}else{

  // 값이 nan이 아닌다

}

 

isnan은 아래와 같이 정의되어 있다.

#define isnan(x)                                                         \

    ( sizeof(x) == sizeof(float)  ? __inline_isnanf((float)(x))          \

    : sizeof(x) == sizeof(double) ? __inline_isnand((double)(x))         \

 

                                  : __inline_isnanl((long double)(x)))

 

그외 다른 방법으로는

[[NSDecimalNumber notANumber] isEqualToNumber:myNumber] 

반응형

'개발자료 > iOS' 카테고리의 다른 글

UIDatePicker  (0) 2014.10.28
NSDate, NSDateFormat  (0) 2014.10.28
UIWebView  (0) 2014.10.28
UILabel  (0) 2014.10.28
[리젝사유] 2.5: Apps that use non-public APIs will be rejected  (0) 2014.10.28