Absolute value of NSInteger

后端 未结 3 1352
走了就别回头了
走了就别回头了 2021-02-11 15:15

Referring to Convert to absolute value in Objective-C I\'m wondering if there are functions for NS typedefed types. Or is abs(NSInteger) okay? Is it architecture-sa

3条回答
  •  青春惊慌失措
    2021-02-11 15:42

    You can use Foundation’s ABS() macro:

    NSInteger a = 5;
    NSInteger b = -5;
    NSLog(@"%ld %ld", ABS(a), ABS(b));
    

提交回复
热议问题