mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Tidied NSNumber descriptions to conform to MacOS-X imnplementation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11370 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d38cfed72d
commit
299c88a96b
5 changed files with 111 additions and 68 deletions
|
@ -1,3 +1,12 @@
|
|||
2001-11-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSNumber.m: describe char and unsigned char as numbers
|
||||
rather than ascii characters. Use g format for floats.
|
||||
Use 'true' and 'false' for boolean output ... for MacOS-X compatibility.
|
||||
* Source/NSConcreteNumber.m: ditto
|
||||
* Source/GSFormat.m: Fix bug in formatting short integers - was trying
|
||||
to treat them as full sized.
|
||||
|
||||
2001-11-09 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Documentation/gsdoc/Base.gsdoc:
|
||||
|
|
|
@ -1158,7 +1158,8 @@ NSDictionary *locale)
|
|||
{
|
||||
long long int signed_number;
|
||||
|
||||
signed_number = args_value[specs[nspecs_done].data_arg].pa_long_long_int;
|
||||
signed_number
|
||||
= args_value[specs[nspecs_done].data_arg].pa_long_long_int;
|
||||
|
||||
is_negative = signed_number < 0;
|
||||
number.longlong = is_negative ? (- signed_number) : signed_number;
|
||||
|
@ -1169,10 +1170,24 @@ NSDictionary *locale)
|
|||
{
|
||||
long int signed_number;
|
||||
|
||||
if (is_long_num)
|
||||
signed_number = args_value[specs[nspecs_done].data_arg].pa_long_int;
|
||||
if (is_char)
|
||||
{
|
||||
signed_number = args_value[specs[nspecs_done].data_arg].pa_char;
|
||||
}
|
||||
else if (is_short)
|
||||
{
|
||||
signed_number
|
||||
= args_value[specs[nspecs_done].data_arg].pa_short_int;
|
||||
}
|
||||
else if (is_long_num)
|
||||
{
|
||||
signed_number
|
||||
= args_value[specs[nspecs_done].data_arg].pa_long_int;
|
||||
}
|
||||
else
|
||||
{
|
||||
signed_number = args_value[specs[nspecs_done].data_arg].pa_int;
|
||||
}
|
||||
|
||||
is_negative = signed_number < 0;
|
||||
number.word = is_negative ? (- signed_number) : signed_number;
|
||||
|
@ -1207,7 +1222,8 @@ NSDictionary *locale)
|
|||
|
||||
if (is_longlong)
|
||||
{
|
||||
number.longlong = args_value[specs[nspecs_done].data_arg].pa_u_long_long_int;
|
||||
number.longlong
|
||||
= args_value[specs[nspecs_done].data_arg].pa_u_long_long_int;
|
||||
|
||||
LABEL (longlong_number):
|
||||
if (prec < 0)
|
||||
|
|
|
@ -40,55 +40,42 @@
|
|||
defined to a number from 0 to 12 cooresponding to each number type */
|
||||
#if TYPE_ORDER == 0
|
||||
# define NumberTemplate NSBoolNumber
|
||||
# define TYPE_FORMAT @"%u"
|
||||
# define TYPE_TYPE BOOL
|
||||
#elif TYPE_ORDER == 1
|
||||
# define NumberTemplate NSCharNumber
|
||||
# define TYPE_FORMAT @"%c"
|
||||
# define TYPE_TYPE signed char
|
||||
#elif TYPE_ORDER == 2
|
||||
# define NumberTemplate NSUCharNumber
|
||||
# define TYPE_FORMAT @"%c"
|
||||
# define TYPE_TYPE unsigned char
|
||||
#elif TYPE_ORDER == 3
|
||||
# define NumberTemplate NSShortNumber
|
||||
# define TYPE_FORMAT @"%hd"
|
||||
# define TYPE_TYPE signed short
|
||||
#elif TYPE_ORDER == 4
|
||||
# define NumberTemplate NSUShortNumber
|
||||
# define TYPE_FORMAT @"%hu"
|
||||
# define TYPE_TYPE unsigned short
|
||||
#elif TYPE_ORDER == 5
|
||||
# define NumberTemplate NSIntNumber
|
||||
# define TYPE_FORMAT @"%d"
|
||||
# define TYPE_TYPE signed int
|
||||
#elif TYPE_ORDER == 6
|
||||
# define NumberTemplate NSUIntNumber
|
||||
# define TYPE_FORMAT @"%u"
|
||||
# define TYPE_TYPE unsigned int
|
||||
#elif TYPE_ORDER == 7
|
||||
# define NumberTemplate NSLongNumber
|
||||
# define TYPE_FORMAT @"%ld"
|
||||
# define TYPE_TYPE signed long
|
||||
#elif TYPE_ORDER == 8
|
||||
# define NumberTemplate NSULongNumber
|
||||
# define TYPE_FORMAT @"%lu"
|
||||
# define TYPE_TYPE unsigned long
|
||||
#elif TYPE_ORDER == 9
|
||||
# define NumberTemplate NSLongLongNumber
|
||||
# define TYPE_FORMAT @"%lld"
|
||||
# define TYPE_TYPE signed long long
|
||||
#elif TYPE_ORDER == 10
|
||||
# define NumberTemplate NSULongLongNumber
|
||||
# define TYPE_FORMAT @"%llu"
|
||||
# define TYPE_TYPE unsigned long long
|
||||
#elif TYPE_ORDER == 11
|
||||
# define NumberTemplate NSFloatNumber
|
||||
# define TYPE_FORMAT @"%0.7f"
|
||||
# define TYPE_TYPE float
|
||||
#elif TYPE_ORDER == 12
|
||||
# define NumberTemplate NSDoubleNumber
|
||||
# define TYPE_FORMAT @"%0.16g"
|
||||
# define TYPE_TYPE double
|
||||
#endif
|
||||
|
||||
|
@ -389,9 +376,31 @@
|
|||
- (NSString*) descriptionWithLocale: (NSDictionary*)locale
|
||||
{
|
||||
#if TYPE_ORDER == 0
|
||||
return (data) ? @"YES" : @"NO";
|
||||
#else
|
||||
return [NSString stringWithFormat: TYPE_FORMAT, data];
|
||||
return (data) ? @"true" : @"false";
|
||||
#elif TYPE_ORDER == 1
|
||||
return [NSString stringWithFormat: @"%i", (int)data];
|
||||
#elif TYPE_ORDER == 2
|
||||
return [NSString stringWithFormat: @"%u", (unsigned int)data];
|
||||
#elif TYPE_ORDER == 3
|
||||
return [NSString stringWithFormat: @"%hi", (short int)data];
|
||||
#elif TYPE_ORDER == 4
|
||||
return [NSString stringWithFormat: @"%hu", (unsigned short int)data];
|
||||
#elif TYPE_ORDER == 5
|
||||
return [NSString stringWithFormat: @"%i", data];
|
||||
#elif TYPE_ORDER == 6
|
||||
return [NSString stringWithFormat: @"%u", data];
|
||||
#elif TYPE_ORDER == 7
|
||||
return [NSString stringWithFormat: @"%li", data];
|
||||
#elif TYPE_ORDER == 8
|
||||
return [NSString stringWithFormat: @"%lu", data];
|
||||
#elif TYPE_ORDER == 9
|
||||
return [NSString stringWithFormat: @"%lli", data];
|
||||
#elif TYPE_ORDER == 10
|
||||
return [NSString stringWithFormat: @"%llu", data];
|
||||
#elif TYPE_ORDER == 11
|
||||
return [NSString stringWithFormat: @"%0.7g", (double)data];
|
||||
#elif TYPE_ORDER == 12
|
||||
return [NSString stringWithFormat: @"%0.16g", data];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -679,42 +679,42 @@ static Class doubleNumberClass;
|
|||
switch (info->typeLevel)
|
||||
{
|
||||
case 0:
|
||||
return [self boolValue] ? @"YES" : @"NO";
|
||||
return [self boolValue] ? @"true" : @"false";
|
||||
case 1:
|
||||
return [NSString stringWithFormat: @"%c",
|
||||
[self charValue]];
|
||||
return [NSString stringWithFormat: @"%i",
|
||||
(int)[self charValue]];
|
||||
case 2:
|
||||
return [NSString stringWithFormat: @"%c",
|
||||
[self unsignedCharValue]];
|
||||
return [NSString stringWithFormat: @"%u",
|
||||
(unsigned int)[self unsignedCharValue]];
|
||||
case 3:
|
||||
return [NSString stringWithFormat: @"%hd",
|
||||
[self shortValue]];
|
||||
return [NSString stringWithFormat: @"%hi",
|
||||
(short int)[self shortValue]];
|
||||
case 4:
|
||||
return [NSString stringWithFormat: @"%hu",
|
||||
[self unsignedShortValue]];
|
||||
(unsigned short int)[self unsignedShortValue]];
|
||||
case 5:
|
||||
return [NSString stringWithFormat: @"%d",
|
||||
return [NSString stringWithFormat: @"%i",
|
||||
[self intValue]];
|
||||
case 6:
|
||||
return [NSString stringWithFormat: @"%u",
|
||||
[self unsignedIntValue]];
|
||||
case 7:
|
||||
return [NSString stringWithFormat: @"%ld",
|
||||
return [NSString stringWithFormat: @"%li",
|
||||
[self longValue]];
|
||||
case 8:
|
||||
return [NSString stringWithFormat: @"%lu",
|
||||
[self unsignedLongValue]];
|
||||
case 9:
|
||||
return [NSString stringWithFormat: @"%lld",
|
||||
return [NSString stringWithFormat: @"%lli",
|
||||
[self longLongValue]];
|
||||
case 10:
|
||||
return [NSString stringWithFormat: @"%llu",
|
||||
[self unsignedLongLongValue]];
|
||||
case 11:
|
||||
return [NSString stringWithFormat: @"%f",
|
||||
[self floatValue]];
|
||||
return [NSString stringWithFormat: @"%0.7g",
|
||||
(double)[self floatValue]];
|
||||
case 12:
|
||||
return [NSString stringWithFormat: @"%g",
|
||||
return [NSString stringWithFormat: @"%0.16g",
|
||||
[self doubleValue]];
|
||||
default:
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
|
|
|
@ -17,7 +17,7 @@ int main()
|
|||
NSRange range;
|
||||
NSRect rect;
|
||||
NSValue *v1, *v2;
|
||||
NSNumber *nc, *ns, *n1, *n2, *n3, *n4, *n5;
|
||||
NSNumber *nc, *ns, *n1, *n2, *n3, *n4, *n5, *n6, *n7;
|
||||
NSArray *a1, *a2;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
|
@ -27,10 +27,19 @@ int main()
|
|||
printf("try %d, %d", [nc charValue], [ns shortValue]);
|
||||
printf("nc compare: ns is %d\n", [nc compare: ns]);
|
||||
n1 = [NSNumber numberWithUnsignedShort: 30];
|
||||
printf("n1 = %s\n", [[n1 description] cString]);
|
||||
n2 = [NSNumber numberWithDouble: 2.7];
|
||||
printf("n2 = %s\n", [[n2 description] cString]);
|
||||
n3 = [NSNumber numberWithDouble: 30];
|
||||
printf("n3 = %s\n", [[n3 description] cString]);
|
||||
n4 = [NSNumber numberWithChar: 111];
|
||||
printf("n4 = %s\n", [[n4 description] cString]);
|
||||
n5 = [NSNumber numberWithChar: 111];
|
||||
printf("n5 = %s\n", [[n5 description] cString]);
|
||||
n6 = [NSNumber numberWithFloat: 1.5];
|
||||
printf("n6 = %s\n", [[n6 description] cString]);
|
||||
n7 = [NSNumber numberWithShort: 25];
|
||||
printf("n7 = %s\n", [[n7 description] cString]);
|
||||
printf("Number(n1) as int %d, as float %f\n",
|
||||
[n1 intValue], [n1 floatValue]);
|
||||
printf("n1 times n2=%f as int to get %d\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue