-
-
Notifications
You must be signed in to change notification settings - Fork 134
Test Stream::parseFloat() with many input digits #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
129ae52
8eb4013
5445db3
fae13e5
1266b08
91c5e29
6197511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
...low when parsing float values. However, we still need to ensure against too large values contained in streams. This should be possible because the maximum length of a float value pre-comma is known to be 38 digits (FLT_MAX_10_EXP).
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
|
||
#include "Common.h" | ||
#include "Stream.h" | ||
#include <math.h> | ||
|
||
#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait | ||
|
||
|
@@ -162,9 +163,9 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore) | |
{ | ||
bool isNegative = false; | ||
bool isFraction = false; | ||
long value = 0; | ||
double value = 0.0; | ||
int c; | ||
float fraction = 1.0; | ||
unsigned int digits_post_comma = 0; | ||
|
||
|
||
c = peekNextDigit(lookahead, true); | ||
// ignore non numeric leading characters | ||
|
@@ -181,7 +182,7 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore) | |
else if(c >= '0' && c <= '9') { // is c a digit? | ||
value = value * 10 + c - '0'; | ||
|
||
if(isFraction) | ||
fraction *= 0.1; | ||
digits_post_comma++; | ||
} | ||
read(); // consume the character we got with peek | ||
c = timedPeek(); | ||
|
@@ -190,10 +191,11 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore) | |
|
||
if(isNegative) | ||
value = -value; | ||
|
||
if(isFraction) | ||
return value * fraction; | ||
else | ||
return value; | ||
value /= pow(10, digits_post_comma); | ||
|
||
|
||
return value; | ||
} | ||
|
||
// read characters from stream into buffer | ||
|