Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -15,10 +15,11 @@ */ #include "config.h" #include +#include #include #include #include #if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) @@ -2517,10 +2518,22 @@ } - (float)floatValue { void *pool = objc_autoreleasePoolPush(); + +#if defined(OF_MORPHOS) && !defined(OF_IXEMUL) + OFString *stripped = [self stringByDeletingEnclosingWhitespaces]; + + if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME || + [stripped caseInsensitiveCompare: @"INFINITY"] == OF_ORDERED_SAME) + return INFINITY; + if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME || + [stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME) + return -INFINITY; +#endif + #ifdef HAVE_STRTOF_L const char *UTF8String = [self UTF8String]; #else /* * If we have no strtof_l, we have no other choice but to replace "." @@ -2558,10 +2571,22 @@ } - (double)doubleValue { void *pool = objc_autoreleasePoolPush(); + +#if defined(OF_MORPHOS) && !defined(OF_IXEMUL) + OFString *stripped = [self stringByDeletingEnclosingWhitespaces]; + + if ([stripped caseInsensitiveCompare: @"INF"] == OF_ORDERED_SAME || + [stripped caseInsensitiveCompare: @"INFINITY"] == OF_ORDERED_SAME) + return INFINITY; + if ([stripped caseInsensitiveCompare: @"-INF"] == OF_ORDERED_SAME || + [stripped caseInsensitiveCompare: @"-INFINITY"] == OF_ORDERED_SAME) + return -INFINITY; +#endif + #ifdef HAVE_STRTOD_L const char *UTF8String = [self UTF8String]; #else /* * If we have no strtod_l, we have no other choice but to replace "." Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -653,11 +653,12 @@ * These test numbers can be generated without rounding if we have IEEE * floating point numbers, thus we can use == on them. */ TEST(@"-[floatValue]", [C(@"\t-0.25 ") floatValue] == -0.25 && - [C(@"\r-INFINITY\n") floatValue] == -INFINITY && + [C(@"\r\n\tINF\t\n") doubleValue] == INFINITY && + [C(@"\r -INFINITY\n") floatValue] == -INFINITY && isnan([C(@" NAN\t\t") floatValue])) #if !defined(OF_ANDROID) && !defined(OF_SOLARIS) && !defined(OF_DJGPP) # define INPUT @"\t-0x1.FFFFFFFFFFFFFP-1020 " # define EXPECTED -0x1.FFFFFFFFFFFFFP-1020 @@ -672,11 +673,12 @@ # define EXPECTED -0.125 # endif #endif TEST(@"-[doubleValue]", [INPUT doubleValue] == EXPECTED && - [C(@"\r-INFINITY\n") doubleValue] == -INFINITY && + [C(@"\r\n\tINF\t\n") doubleValue] == INFINITY && + [C(@"\r -INFINITY\n") doubleValue] == -INFINITY && isnan([C(@" NAN\t\t") doubleValue])) #undef INPUT #undef EXPECTED EXPECT_EXCEPTION(@"Detect invalid characters in -[decimalValue] #1",