From 172e6e5e8bb18c1acd764657fc488aea01623633 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Thu, 29 Oct 2009 19:26:47 +0000 Subject: [PATCH] Fixed problem with negative exponents in floating point constants (issue #62) git-svn-id: http://picoc.googlecode.com/svn/trunk@355 21eae674-98b7-11dd-bd71-f92a316d2d60 --- lex.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lex.c b/lex.c index c08de3d..a857558 100644 --- a/lex.c +++ b/lex.c @@ -174,11 +174,19 @@ enum LexToken LexGetNumber(struct LexState *Lexer, struct Value *Value) if (Lexer->Pos != Lexer->End && (*Lexer->Pos == 'e' || *Lexer->Pos == 'E')) { + double ExponentMultiplier = 1.0; + LEXER_INC(Lexer); + if (Lexer->Pos != Lexer->End && *Lexer->Pos == '-') + { + ExponentMultiplier = -1.0; + LEXER_INC(Lexer); + } + for (Result = 0; Lexer->Pos != Lexer->End && IS_BASE_DIGIT(*Lexer->Pos, Base); LEXER_INC(Lexer)) Result = Result * (double)Base + GET_BASE_DIGIT(*Lexer->Pos); - FPResult *= math_pow((double)Base, (double)Result); + FPResult *= math_pow((double)Base, (double)Result * ExponentMultiplier); } Value->Val->FP = FPResult;