Skip to content

Commit

Permalink
Add scientific notation support to Decimal::setDecimal
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdelv committed Aug 22, 2024
1 parent 1d76ff1 commit e1fa0fc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions rtl/nbcd/nbcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,13 @@ void Decimal::setReal(double value)
void Decimal::setString(size32_t length, const char * buffer)
{
const char * limit = buffer+length;
const char * cur = buffer;
const char * cur = limit;
int sciNotation = 0;
while ((cur > buffer) && (*cur != 'E'))
cur--;
if (cur != buffer)
sciNotation = atoi(std::string(cur+1, limit).c_str());
cur = buffer;
while ((cur < limit) && (*cur == ' '))
cur++;

Expand All @@ -975,8 +981,8 @@ void Decimal::setString(size32_t length, const char * buffer)

int idx;
for (idx = 0; idx < (int)numDigits; idx++)
digits[zeroDigit+idx] = cur[-(idx+1)] - '0'; // careful - if idx is unsigned, -(idx+1) is not sign-extended and fails if int size is not pointer size
msb = zeroDigit+(numDigits-1);
digits[zeroDigit+idx+sciNotation] = cur[-(idx+1)] - '0'; // careful - if idx is unsigned, -(idx+1) is not sign-extended and fails if int size is not pointer size
msb = zeroDigit+(numDigits-1)+sciNotation;

if ((cur < limit) && (*cur == '.'))
{
Expand All @@ -985,13 +991,13 @@ void Decimal::setString(size32_t length, const char * buffer)
const char * start = cur;
if (limit-cur > maxPrecision)
limit = cur + maxPrecision;
byte * digit = digits + zeroDigit;
byte * digit = digits + zeroDigit + sciNotation;
while ((cur < limit) && (isdigit(*cur)))
*--digit = *cur++ - '0';
lsb = zeroDigit - (cur-start);
lsb = zeroDigit - (cur-start) + sciNotation;
}
else
lsb = zeroDigit;
lsb = zeroDigit + sciNotation;
}


Expand Down

0 comments on commit e1fa0fc

Please sign in to comment.