Re: NSNumber Bug I can't fix

2011-02-18 Thread Marcus Müller
Hi Richard,

> Thanks, I added a quick hack to try to fix this and put a few very simple 
> tests in 
> svn://svn.gna.org/svn/gnustep/libs/base/trunk/Tests/base/NSNumber/test01.m


thanks for the quick response & hotfix. I can confirm that it works here 
(FreeBSD 8.2rc3 amd64).

Cheers,

  Marcus

-- 
Marcus Mueller  .  .  .  crack-admin/coder ;-)
Mulle kybernetiK  .  http://www.mulle-kybernetik.com
Current projects: http://www.mulle-kybernetik.com/znek/




smime.p7s
Description: S/MIME cryptographic signature
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSNumber Bug I can't fix

2011-02-17 Thread Richard Frith-Macdonald

On 17 Feb 2011, at 16:01, Marcus Müller wrote:

> 
>> As you can see above, asking an NSIntNumber instance for its doubleValue 
>> works properly, however, it fails at NSNumber.m:165. I don't know the 
>> reason, but I also don't understand the implications of the macros used. Can 
>> somebody elaborate? Please note that I'm on a 64-bit (amd64) system.
> 
> Thinking about it, I guess my hint was pretty bogus. I believe the real 
> problem here is the COMPARE macro which compares a double with a NaN, which 
> simply won't work:
> 
> #define COMPARE(value, other) \
> if (value < other)\
>   {\
> return NSOrderedAscending;\
>   }\
> if (value > other)\
>   {\
> return NSOrderedDescending;\
>   }\
> return NSOrderedSame;
> 
> If either is a nan, this will return NSOrderedSame which is, well, not 
> incorrect. However, in the context of NSNumber.m:165 it returns a wrong 
> result.
> 
> This raises the question, what should be done to - (NSComparisonResult) 
> compare: (NSNumber*)aNumber?
> Comparing a NaN with another number is undefined and might lead to 
> NSOrderedSame, but it should never lead to [2 isEqualToNumber:NaN] == YES. 
> I'm not sure how to fix this properly, but not returning NSOrderedSame in 
> this case would certainly help.

Thanks, I added a quick hack to try to fix this and put a few very simple tests 
in svn://svn.gna.org/svn/gnustep/libs/base/trunk/Tests/base/NSNumber/test01.m


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSNumber Bug I can't fix

2011-02-17 Thread Jens Ayton
For reference, under Mac OS X 10.6.6:

2 compare: nan = NSOrderedDescending
nan compare: 2 = NSOrderedAscending
nan compare: nan = NSOrderedSame
2 isEqual: nan = NO
nan isEqual: n = NO
nan isEqual: nan = YES

Just for fun, I tried it with [NSNumber numberWithDouble:INFINITY] instead of 2:

inf compare: nan = NSOrderedDescending
nan compare: inf = NSOrderedAscending
-inf compare: nan = NSOrderedAscending
nan compare: -inf = NSOrderedDescending

-- 
Jens Ayton


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: NSNumber Bug I can't fix

2011-02-17 Thread Marcus Müller

> As you can see above, asking an NSIntNumber instance for its doubleValue 
> works properly, however, it fails at NSNumber.m:165. I don't know the reason, 
> but I also don't understand the implications of the macros used. Can somebody 
> elaborate? Please note that I'm on a 64-bit (amd64) system.

Thinking about it, I guess my hint was pretty bogus. I believe the real problem 
here is the COMPARE macro which compares a double with a NaN, which simply 
won't work:

#define COMPARE(value, other) \
if (value < other)\
  {\
return NSOrderedAscending;\
  }\
if (value > other)\
  {\
return NSOrderedDescending;\
  }\
return NSOrderedSame;

If either is a nan, this will return NSOrderedSame which is, well, not 
incorrect. However, in the context of NSNumber.m:165 it returns a wrong result.

This raises the question, what should be done to - (NSComparisonResult) 
compare: (NSNumber*)aNumber?
Comparing a NaN with another number is undefined and might lead to 
NSOrderedSame, but it should never lead to [2 isEqualToNumber:NaN] == YES. I'm 
not sure how to fix this properly, but not returning NSOrderedSame in this case 
would certainly help.

Cheers,

  Marcus

-- 
Marcus Mueller  .  .  .  crack-admin/coder ;-)
Mulle kybernetiK  .  http://www.mulle-kybernetik.com
Current projects: http://www.mulle-kybernetik.com/znek/




smime.p7s
Description: S/MIME cryptographic signature
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev


NSNumber Bug I can't fix

2011-02-17 Thread Marcus Müller
Hi,

I just stumbled across a bug in NSNumber that I can't fix as I don't understand 
the NSNumber code. The problem is easy to see, though:

#import 

int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSNumber *n   = [NSNumber numberWithInt:2];
NSNumber *nan = [NSDecimalNumber notANumber];

NSLog(@"%@ (class:%@ double:%g) == %@ -> %s",
  n, NSStringFromClass([n class]), [n doubleValue],
  nan, [n isEqualToNumber:nan] ? "YES" : "NO");

[pool release];
return 0;
}

On FreeBSD-8.2rc3 (amd64) this produces the following output:
2011-02-17 16:02:15.316 NumberTest[59574] 2 (class:NSIntNumber double:2) == NaN 
-> YES
Which is clearly wrong.

I came across this issue via NSNumberFormatter, which instead of formatting any 
integer numbers always printed NaN. In my project  I tried to debug into the 
issue and found this:
769   if ([anObject isEqual: [NSDecimalNumber notANumber]])
(gdb) s
-[NSNumber isEqual:] (self=0x803e8d1d0, _cmd=0x801410980, anObject=0x805e625c0)
at NSNumber.m:376
376   if ([anObject isKindOfClass: NSNumberClass])
(gdb) n
378   return [self isEqualToNumber: anObject];
(gdb) po anObject
NaN
(gdb) po [anObject class]
NSDecimalNumber
(gdb) s
-[NSNumber isEqualToNumber:] (self=0x803e8d1d0, _cmd=0x80140d300, 
aNumber=0x805e625c0) at NSNumber.m:371
371   return ([self compare: aNumber] == NSOrderedSame) ? YES : NO;
(gdb) s
-[NSSignedIntegerNumber compare:] (self=0x803e8d1d0, _cmd=0x80140d2e0, 
aNumber=0x805e625c0) at NSNumber.m:107
107   if (aNumber == self)
[…]
(gdb) n
165   double value = [self doubleValue];
(gdb) p other
$3 = nan(0x8)
(gdb) p value
$4 = 6.9533556002420585e-310

As you can see above, asking an NSIntNumber instance for its doubleValue works 
properly, however, it fails at NSNumber.m:165. I don't know the reason, but I 
also don't understand the implications of the macros used. Can somebody 
elaborate? Please note that I'm on a 64-bit (amd64) system.

Thanks,

  Marcus

-- 
Marcus Mueller  .  .  .  crack-admin/coder ;-)
Mulle kybernetiK  .  http://www.mulle-kybernetik.com
Current projects: http://www.mulle-kybernetik.com/znek/




smime.p7s
Description: S/MIME cryptographic signature
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev