james-collinss-macbook-prorog15 jamescollins$ ./prog15.1
100
abcdef
X
100
nan
0
Numbers are equal
First number is less than second
got this output while i tried to compile and run a program from a book on objective-c by Stephen G. Kochan.
here is my program. which i called prog15.1.m
100
abcdef
X
100
nan
0
Numbers are equal
First number is less than second
got this output while i tried to compile and run a program from a book on objective-c by Stephen G. Kochan.
here is my program. which i called prog15.1.m
Code:
// working with numbers
#import <Foundation/NSObject.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSString.h>
#import <stdio.h>
int main (int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSNumber *myNumber, *floatNumber, *intNumber;
int i;
// integer value
intNumber = [NSNumber numberWithInt: 100];
printf ("%i\n", [intNumber intValue]);
// long value
myNumber = [NSNumber numberWithLong: 0xabcdef];
printf ("%lx\n", [myNumber longValue]);
// char value
myNumber = [NSNumber numberWithChar: 'X'];
printf ("%c\n", [myNumber charValue]);
// float value
floatNumber = [NSNumber numberWithFloat: 100.00];
printf ("%g\n", [floatNumber floatValue]);
// double
myNumber = [NSNumber numberWithDouble: 12345e+15];
printf ("%Lg\n", [myNumber intValue]);
// wrong access here
printf ("%i\n", [myNumber intValue]);
// Test two Numbers for equality
if ([intNumber isEqualToNumber: floatNumber] == YES)
printf ("Numbers are equal\n");
else
printf ("Numbers are not equal\n");
// Test if one Number is <, ==, or > second Number
if ([intNumber compare: myNumber] == NSOrderedAscending)
printf ("First number is less than second\n");
[pool release];
return 0;
}
[code\]
the output from the book is as follows.
100
abcdef
X
100
1.2345e+19
2147483647
Numbers are equal
First number is less than second
just wondering why my output doesen't match the book's.