From af5a200a68ed12efec4b29b57fa22c632aaf91fa Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Thu, 19 Jun 2008 19:01:31 +0200 Subject: Fix number parsing. --- MLKSingleFloat.m | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'MLKSingleFloat.m') diff --git a/MLKSingleFloat.m b/MLKSingleFloat.m index 76965ec..85cc934 100644 --- a/MLKSingleFloat.m +++ b/MLKSingleFloat.m @@ -16,12 +16,16 @@ * along with this program. If not, see . */ +#define _XOPEN_SOURCE 600 // strtof + #import "MLKSingleFloat.h" #import "MLKDoubleFloat.h" #import #include +#include +#include @implementation MLKSingleFloat @@ -32,6 +36,13 @@ exponentNegative:(BOOL)exponentNegative { self = [super init]; + char *locale; + + // FIXME: This is probably not thread-safe. + locale = setlocale (LC_NUMERIC, NULL); + setlocale (LC_NUMERIC, "C"); + + // strtof or sscanf -- is there a difference? sscanf ([[NSString stringWithFormat:@"%c%@.%@e%c%@", (negative ? '-' : '+'), intPart, @@ -41,6 +52,9 @@ UTF8String], "%f", &value); + + setlocale (LC_NUMERIC, locale); + return self; } -- cgit v1.2.3