Commit 548a9ea3 authored by Over_score's avatar Over_score

Merge branch 'patch-1' into 'master'

Do not nest functions

See merge request !399
parents 3daef7cc d0447ac1
......@@ -223,57 +223,59 @@ void addItemToBuffer(uint16_t item) {
void addItemToNimBuffer(int16_t item) {
bool_t isRealDp(const char *buffer) {
int16_t firstDigit, lastDigit, numDigits, decimalSeparator, exponent, exponentLocation;
//printf(" %s : ", buffer);
// The first digit is the first character that is neither a . nor a 0
firstDigit = 0;
while(buffer[firstDigit] != 0 && (buffer[firstDigit] == '0' || buffer[firstDigit] == '.')) {
firstDigit++;
}
if(buffer[firstDigit] == 0) {
lastDigit = firstDigit;
static bool_t isRealDp(const char *buffer) {
int16_t firstDigit, lastDigit, numDigits, decimalSeparator, exponent, exponentLocation;
//printf(" %s : ", buffer);
// The first digit is the first character that is neither a . nor a 0
firstDigit = 0;
while(buffer[firstDigit] != 0 && (buffer[firstDigit] == '0' || buffer[firstDigit] == '.')) {
firstDigit++;
}
if(buffer[firstDigit] == 0) {
lastDigit = firstDigit;
}
else {
// The last digit is the last character that is neither a . nor a 0
lastDigit = firstDigit;
while(buffer[lastDigit] != 0 && buffer[lastDigit] != 'e' && buffer[lastDigit] != '+' && buffer[lastDigit] != '-') {
lastDigit++;
}
else {
// The last digit is the last character that is neither a . nor a 0
lastDigit = firstDigit;
while(buffer[lastDigit] != 0 && buffer[lastDigit] != 'e' && buffer[lastDigit] != '+' && buffer[lastDigit] != '-') {
lastDigit++;
}
lastDigit--;
lastDigit--;
while(buffer[lastDigit] == '0' || buffer[lastDigit] == '.') {
lastDigit--;
}
while(buffer[lastDigit] == '0' || buffer[lastDigit] == '.') {
lastDigit--;
}
}
for(decimalSeparator=0; buffer[decimalSeparator]!=0 && buffer[decimalSeparator]!='.'; decimalSeparator++);
for(decimalSeparator=0; buffer[decimalSeparator]!=0 && buffer[decimalSeparator]!='.'; decimalSeparator++);
numDigits = lastDigit - firstDigit + (firstDigit<=decimalSeparator && decimalSeparator<=lastDigit ? 0 : 1);
//printf("firstDigit=%d lastDigit=%d numDigits=%d decimalSeparator=%d\n", firstDigit, lastDigit, numDigits, decimalSeparator);
numDigits = lastDigit - firstDigit + (firstDigit<=decimalSeparator && decimalSeparator<=lastDigit ? 0 : 1);
//printf("firstDigit=%d lastDigit=%d numDigits=%d decimalSeparator=%d\n", firstDigit, lastDigit, numDigits, decimalSeparator);
if(numDigits > 16) {
return true;
if(numDigits > 16) {
return true;
}
else {
exponentLocation = 0;
while(buffer[exponentLocation] != 0 && buffer[exponentLocation] != 'e') {
exponentLocation++;
}
else {
exponentLocation = 0;
while(buffer[exponentLocation] != 0 && buffer[exponentLocation] != 'e') {
exponentLocation++;
}
if(buffer[exponentLocation] == 'e') {
exponent = atoi(buffer + exponentLocation + 1);
//printf(" exponentLocation=%d exponent=%d\n", exponentLocation, exponent);
exponent += decimalSeparator - firstDigit - (decimalSeparator > firstDigit ? 1 : 0);
//printf(" corrected exponent=%d\n", exponent);
return (exponent < -383 || exponent > 384);
}
if(buffer[exponentLocation] == 'e') {
exponent = atoi(buffer + exponentLocation + 1);
//printf(" exponentLocation=%d exponent=%d\n", exponentLocation, exponent);
exponent += decimalSeparator - firstDigit - (decimalSeparator > firstDigit ? 1 : 0);
//printf(" corrected exponent=%d\n", exponent);
return (exponent < -383 || exponent > 384);
}
return false;
}
return false;
}
void addItemToNimBuffer(int16_t item) {
int16_t lastChar, index;
uint8_t savedNimNumberPart;
bool_t done;
......@@ -1054,33 +1056,35 @@ void addItemToNimBuffer(int16_t item) {
void nimBufferToDisplayBuffer(const char *nimBuffer, char *displayBuffer) {
int16_t insertGapIP(char *displayBuffer, int16_t numDigits, int16_t nth) {
if(groupingGap == 0) return 0; // no gap when none is required!
if(numDigits <= groupingGap) return 0; // there are less than groupingGap digits
if(nth + 1 == numDigits) return 0; // no gap after the last digit
if((numDigits - nth) % groupingGap == 1 || groupingGap == 1) {
strcpy(displayBuffer, NUM_SPACE_PUNCTUATION);
return 2;
}
static int16_t insertGapIP(char *displayBuffer, int16_t numDigits, int16_t nth) {
if(groupingGap == 0) return 0; // no gap when none is required!
if(numDigits <= groupingGap) return 0; // there are less than groupingGap digits
if(nth + 1 == numDigits) return 0; // no gap after the last digit
return 0;
if((numDigits - nth) % groupingGap == 1 || groupingGap == 1) {
strcpy(displayBuffer, NUM_SPACE_PUNCTUATION);
return 2;
}
int16_t insertGapFP(char *displayBuffer, int16_t numDigits, int16_t nth) {
if(groupingGap == 0) return 0; // no gap when none is required!
if(numDigits <= groupingGap) return 0; // there are less than groupingGap digits
if(nth + 1 == numDigits) return 0; // no gap after the last digit
return 0;
}
if(nth % groupingGap == groupingGap - 1) {
strcpy(displayBuffer, NUM_SPACE_PUNCTUATION);
return 2;
}
static int16_t insertGapFP(char *displayBuffer, int16_t numDigits, int16_t nth) {
if(groupingGap == 0) return 0; // no gap when none is required!
if(numDigits <= groupingGap) return 0; // there are less than groupingGap digits
if(nth + 1 == numDigits) return 0; // no gap after the last digit
return 0;
if(nth % groupingGap == groupingGap - 1) {
strcpy(displayBuffer, NUM_SPACE_PUNCTUATION);
return 2;
}
return 0;
}
void nimBufferToDisplayBuffer(const char *nimBuffer, char *displayBuffer) {
int16_t numDigits, source, dest;
if(*nimBuffer == '-') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment