diff options
author | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-19 19:01:31 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <matthias@benkard.de> | 2008-06-19 19:01:31 +0200 |
commit | af5a200a68ed12efec4b29b57fa22c632aaf91fa (patch) | |
tree | bdbec22869a15b2a41371a2507a74b852ee6704e /MLKSingleFloat.m | |
parent | f9f90837641694619d184cf2ab8b5c03c46b08dd (diff) |
Fix number parsing.
Diffstat (limited to 'MLKSingleFloat.m')
-rw-r--r-- | MLKSingleFloat.m | 14 |
1 files changed, 14 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. */ +#define _XOPEN_SOURCE 600 // strtof + #import "MLKSingleFloat.h" #import "MLKDoubleFloat.h" #import <Foundation/NSString.h> #include <stdio.h> +#include <stdlib.h> +#include <locale.h> @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; } |