Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a constant which defines the max value of long or integer?

In java, there is a constant for the max value of Long. Such as:

long minBillId = Long.MAX_VALUE

Is there a constant for the max value of long or int in Obj-C?

like image 756
理想评论学派 Avatar asked Mar 18 '12 17:03

理想评论学派


People also ask

What is the max value of a long?

long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).

What is max value of integer in Java?

The int type in Java can be used to represent any whole number from -2147483648 to 2147483647. Why those numbers? Integers in Java are represented in 2's complement binary and each integer gets 32 bits of space.

What is max value of long in Java?

long: The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1.


3 Answers

If you import limits.h you can call LONG_MAX

For reference this site shows how to get the max for all types as such:

#import <limits.h>  // ... NSLog(@"CHAR_MIN:   %c",   CHAR_MIN); NSLog(@"CHAR_MAX:   %c",   CHAR_MAX); NSLog(@"SHRT_MIN:   %hi",  SHRT_MIN);    // signed short int   NSLog(@"SHRT_MAX:   %hi",  SHRT_MAX); NSLog(@"INT_MIN:    %i",   INT_MIN); NSLog(@"INT_MAX:    %i",   INT_MAX); NSLog(@"LONG_MIN:   %li",  LONG_MIN);    // signed long int NSLog(@"LONG_MAX:   %li",  LONG_MAX); NSLog(@"ULONG_MIN not defined, it's always zero: %lu", 0);   NSLog(@"ULONG_MAX:  %lu",  ULONG_MAX);   // unsigned long int NSLog(@"LLONG_MIN:  %lli", LLONG_MIN);   // signed long long int NSLog(@"LLONG_MAX:  %lli", LLONG_MAX); NSLog(@"ULLONG_MIN not defined, it's always zero: %llu", 0);   NSLog(@"ULLONG_MAX: %llu", ULLONG_MAX);  // unsigned long long int 
like image 144
Amit Shah Avatar answered Sep 19 '22 00:09

Amit Shah


INT_MAX should resolve to 2147483647

This:

#import <Foundation/Foundation.h>  int main (int argc, const char * argv[]) {     NSInteger foo = INT_MAX;     NSLog(@"foo: %li", foo);  // li because 64 bit OSX cmd line app      return 0; } 

Outputs:

2012-03-18 13:58:54.509 Craplet[51324:707] foo: 2147483647 
like image 29
bryanmac Avatar answered Sep 18 '22 00:09

bryanmac


  NSLog(@"INT_MIN:    %i",   INT_MIN);
  NSLog(@"INT_MAX:    %i",   INT_MAX);
  NSLog(@"LONG_MIN:   %li",  LONG_MIN); 
  NSLog(@"LONG_MAX:   %li",  LONG_MAX);
like image 44
Jason Avatar answered Sep 21 '22 00:09

Jason