Skip to content

Commit 1266b08

Browse files
committed
Replacing computational expensive pow call with result of accumulated multiplication.
1 parent fae13e5 commit 1266b08

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

api/Stream.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "Common.h"
2626
#include "Stream.h"
27-
#include <math.h>
2827

2928
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
3029

@@ -165,7 +164,7 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
165164
bool isFraction = false;
166165
double value = 0.0;
167166
int c;
168-
unsigned int digits_post_comma = 0;
167+
double fraction = 1.0;
169168

170169
c = peekNextDigit(lookahead, true);
171170
// ignore non numeric leading characters
@@ -182,7 +181,7 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
182181
else if(c >= '0' && c <= '9') { // is c a digit?
183182
value = value * 10 + c - '0';
184183
if(isFraction)
185-
digits_post_comma++;
184+
fraction *= 0.1;
186185
}
187186
read(); // consume the character we got with peek
188187
c = timedPeek();
@@ -193,7 +192,7 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
193192
value = -value;
194193

195194
if(isFraction)
196-
value /= pow(10, digits_post_comma);
195+
value *= fraction;
197196

198197
return value;
199198
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy