Commit a17a4a8b authored by Over_score's avatar Over_score

Using 72 digit reals for slvq

parent ec0da78e
This diff is collapsed.
......@@ -46,12 +46,13 @@ bool_t allowScreenUpdate;
bool_t funcOK;
// Variables stored in RAM
decContext ctxtReal16; // 16 digits
decContext ctxtReal34; // 34 digits
decContext ctxtRealIc; // 39 digits: used for 34 digits intermediate calculations
decContext ctxtReal51; // 51 digits: used in trigonometric function from WP34S
decContext ctxtReal451; // 451 digits: used in radian angle reduction
decContext ctxtReal850; // 850 digits: used for really big modulo
realContext_t ctxtReal16; // 16 digits
realContext_t ctxtReal34; // 34 digits
realContext_t ctxtReal39; // 39 digits: used for 34 digits intermediate calculations
realContext_t ctxtReal51; // 51 digits: used in trigonometric function from WP34S
realContext_t ctxtReal75; // 75 digits: used in SLVQ
realContext_t ctxtReal459; // 459 digits: used in radian angle reduction
realContext_t ctxtReal855; // 855 digits: used for really big modulo
uint16_t flags[7];
char tmpStr3000[TMP_STR_LENGTH];
char errorMessage[ERROR_MESSAGE_LENGTH];
......@@ -162,10 +163,10 @@ size_t wp43sMemInBytes;
freeBlock_t freeBlocks[MAX_FREE_BLOCKS];
int32_t numberOfFreeBlocks;
void (*confirmedFunction)(uint16_t);
realIc_t const *gammaConstants;
realIc_t const *angle180;
realIc_t const *angle90;
realIc_t const *angle45;
real39_t const *gammaConstants;
real39_t const *angle180;
real39_t const *angle90;
real39_t const *angle45;
#ifdef DMCP_BUILD
bool_t endOfProgram;
uint32_t nextScreenRefresh; // timer substitute for refreshScreen(), which does cursor blinking and other stuff
......@@ -249,6 +250,7 @@ int main(int argc, char* argv[]) {
/****************/
/* Catalog FCNS */
/****************/
printf("Generating catalog FCNS\n");
fprintf(catalog, "const int16_t menu_FCNS[] = {\n");
numberOfItems = 0;
......@@ -281,6 +283,7 @@ int main(int argc, char* argv[]) {
/****************/
/* Catalog CNST */
/****************/
printf("Generating catalog CNST\n");
fprintf(catalog, "\n\nconst int16_t menu_CNST[] = {\n");
numberOfItems = 0;
......@@ -313,6 +316,7 @@ int main(int argc, char* argv[]) {
/*****************/
/* Catalog MENUS */
/*****************/
printf("Generating catalog MENUS\n");
fprintf(catalog, "\n\nconst int16_t menu_MENUS[] = {\n");
numberOfItems = 0;
......
......@@ -19,7 +19,6 @@
***********************************************/
#define IBM_DECIMAL 1
#define DIGITS_FOR_34_DIGITS_INTERMEDIATE_CALCULATIONS 39
#define NUMBER_OF_CONSTANTS_IN_CNST_CATALOG 79
#include <stdlib.h>
......@@ -32,7 +31,7 @@
#endif // __APPLE__
#if (IBM_DECIMAL == 1)
#define DECNUMDIGITS DIGITS_FOR_34_DIGITS_INTERMEDIATE_CALCULATIONS
#define DECNUMDIGITS 39
#include "decimal128.h"
#include "decimal64.h"
#include "decDouble.h"
......@@ -40,25 +39,74 @@
#include "decNumberWrappers.h"
#endif
decContext ctxtRealIc; // Intermediate calculations for 34 digits
decContext ctxtReal16, ctxtReal34, ctxtReal451;
realContext_t ctxtReal16, ctxtReal34, ctxtReal39, ctxtReal459;
char whiteSpace[50], temp[1000];
char whiteSpace[50], temp[10000];
char defines[1000000], externalDeclarations[1000000]; // .h file
char realArray[1000000], realPointerDeclarations[1000000], real16PointerDeclarations[1000000], real34PointerDeclarations[1000000], real451PointerDeclarations[1000000]; // .c file
char realArray[1000000], realPointerDeclarations[1000000], real16PointerDeclarations[1000000], real34PointerDeclarations[1000000], real459PointerDeclarations[1000000]; // .c file
FILE *constantsC, *constantsH;
int idx, c;
void printRealToConsole(const real_t *value) {
int32_t i, exponent, last;
if(realIsNaN(value)) {
printf("NaN");
return;
}
if(realIsNegative(value)) {
printf("-");
}
if(realIsInfinite(value)) {
printf("infinite");
return;
}
if(realIsZero(value)) {
printf("0");
return;
}
if(value->digits % DECDPUN) {
i = value->digits/DECDPUN;
}
else {
i = value->digits/DECDPUN - 1;
}
while(value->lsu[i] == 0) i--;
printf("%u", value->lsu[i--]);
exponent = value->exponent;
last = 0;
while(exponent <= -DECDPUN && value->lsu[last] == 0) {
last++;
exponent += DECDPUN;
}
for(; i>=last; i--) {
printf(" %03u", value->lsu[i]);
}
if(exponent != 0) {
printf(" e %d", exponent);
}
}
void generateConstantArray(char *name, char *value) {
realIc_t realIc;
real39_t real39;
printf("generateConstantArray: %-10.10s = %s\n", name, value);
memset(&realIc, 0, sizeof(realIc));
stringToRealIc(value, &realIc);
memset(&real39, 0, REAL39_SIZE);
stringToReal(value, &real39, &ctxtReal39);
strcpy(whiteSpace, " ");
whiteSpace[13 - strlen(name)] = 0;
strcat(externalDeclarations, "extern const realIc_t * const const_");
strcat(externalDeclarations, "extern const real_t * const const_");
strcat(externalDeclarations, name);
strcat(externalDeclarations, ";\n");
......@@ -67,18 +115,18 @@ void generateConstantArray(char *name, char *value) {
strcat(defines, temp);
}
strcat(realPointerDeclarations, "const realIc_t * const const_");
strcat(realPointerDeclarations, "const real_t * const const_");
strcat(realPointerDeclarations, name);
strcat(realPointerDeclarations, whiteSpace);
strcat(realPointerDeclarations, " = (realIc_t *)(constants + ");
strcat(realPointerDeclarations, " = (real_t *)(constants + ");
sprintf(temp, "%5d)", idx);
idx += sizeof(realIc_t);
idx += REAL39_SIZE;
strcat(realPointerDeclarations, temp);
strcat(realPointerDeclarations, ";\n");
strcat(realArray, " ");
for(uint32_t i=0; i<sizeof(realIc_t); i++) {
sprintf(temp, "0x%02x,", *(((uint8_t *)(&realIc)) + i));
for(uint32_t i=0; i<REAL39_SIZE; i++) {
sprintf(temp, "0x%02x,", *(((uint8_t *)(&real39)) + i));
strcat(realArray, temp);
}
......@@ -91,7 +139,9 @@ void generateConstantArray(char *name, char *value) {
void generateConstantArray16(char *name, char *value) {
real16_t real16;
memset(&real16, 0, sizeof(real16_t));
printf("generateConstantArray16: %-10.10s = %s\n", name, value);
memset(&real16, 0, REAL16_SIZE);
stringToReal16(value, &real16);
strcpy(whiteSpace, " ");
......@@ -125,7 +175,9 @@ void generateConstantArray16(char *name, char *value) {
void generateConstantArray34(char *name, char *value) {
real34_t real34;
memset(&real34, 0, sizeof(real34_t));
printf("generateConstantArray34: %-10.10s = %s\n", name, value);
memset(&real34, 0, REAL34_SIZE);
stringToReal34(value, &real34);
strcpy(whiteSpace, " ");
......@@ -156,31 +208,33 @@ void generateConstantArray34(char *name, char *value) {
}
void generateConstantArray451(char *name, char *value) {
real451_t real451;
void generateConstantArray459(char *name, char *value) {
real459_t real459;
printf("generateConstantArray459: %-10.10s = %s\n", name, value);
memset(&real451, 0, sizeof(real451_t));
stringToRealIc(value, &real451);
memset(&real459, 0, REAL459_SIZE);
stringToReal(value, &real459, &ctxtReal459);
strcpy(whiteSpace, " ");
whiteSpace[10 - strlen(name)] = 0;
strcat(externalDeclarations, "extern const realIc_t * const const451_");
strcat(externalDeclarations, "extern const real_t * const const459_");
strcat(externalDeclarations, name);
strcat(externalDeclarations, ";\n");
strcat(real451PointerDeclarations, "const realIc_t * const const451_");
strcat(real451PointerDeclarations, name);
strcat(real451PointerDeclarations, whiteSpace);
strcat(real451PointerDeclarations, " = (realIc_t *)(constants + ");
strcat(real459PointerDeclarations, "const real_t * const const459_");
strcat(real459PointerDeclarations, name);
strcat(real459PointerDeclarations, whiteSpace);
strcat(real459PointerDeclarations, " = (real_t *)(constants + ");
sprintf(temp, "%5d)", idx);
idx += sizeof(real451_t);
strcat(real451PointerDeclarations, temp);
strcat(real451PointerDeclarations, ";\n");
idx += REAL459_SIZE;
strcat(real459PointerDeclarations, temp);
strcat(real459PointerDeclarations, ";\n");
strcat(realArray, " ");
for(uint32_t i=0; i<sizeof(real451_t); i++) {
sprintf(temp, "0x%02x,", *(((uint8_t *)(&real451)) + i));
for(uint32_t i=0; i<REAL459_SIZE; i++) {
sprintf(temp, "0x%02x,", *(((uint8_t *)(&real459)) + i));
strcat(realArray, temp);
}
......@@ -511,11 +565,11 @@ void generateAllConstants(void) {
generateConstantArray("1e6", "+1.000000000000000000000000000000000000000000000000000000e+06");
generateConstantArray("2p32", "+4.294967296000000000000000000000000000000000000000000000e+09");
generateConstantArray451("2pi", "+6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359"
generateConstantArray459("2pi", "+6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696506842341359"
"6429617302656461329418768921910116446345071881625696223490056820540387704221111928924589790986076392"
"8857621951331866892256951296467573566330542403818291297133846920697220908653296426787214520498282547"
"4491740132126311763497630418419256585081834307287357851807200226610610976409330427682939038830232188"
"66114540731519183906184372234763865223586210237096148924759925499134703771505449782455876366e+00");
"66114540731519183906184372234763865223586210237096148924759925499134703771505449782455876366e+00"); // 493 digits
generateConstantArray16("0", "+0.000000000000000000000000000000000000000000000000000000e+00");
generateConstantArray16("1e_4", "+1.000000000000000000000000000000000000000000000000000000e-04");
......@@ -556,14 +610,14 @@ int main(int argc, char* argv[]) {
int main(void) {
#endif
decContextDefault(&ctxtRealIc, DEC_INIT_DECQUAD);
decContextDefault(&ctxtReal16, DEC_INIT_DECDOUBLE);
decContextDefault(&ctxtReal34, DEC_INIT_DECQUAD);
decContextDefault(&ctxtReal451, DEC_INIT_DECQUAD);
ctxtRealIc.digits = DIGITS_FOR_34_DIGITS_INTERMEDIATE_CALCULATIONS;
ctxtRealIc.traps = 0;
ctxtReal451.digits = 451;
ctxtReal451.traps = 0;
decContextDefault(&ctxtReal39, DEC_INIT_DECQUAD);
decContextDefault(&ctxtReal459, DEC_INIT_DECQUAD);
ctxtReal39.digits = 39;
ctxtReal39.traps = 0;
ctxtReal459.digits = 450;
ctxtReal459.traps = 0;
defines[0] = 0;
externalDeclarations[0] = 0;
......@@ -572,7 +626,7 @@ int main(void) {
realPointerDeclarations[0] = 0;
real16PointerDeclarations[0] = 0;
real34PointerDeclarations[0] = 0;
real451PointerDeclarations[0] = 0;
real459PointerDeclarations[0] = 0;
generateAllConstants();
......@@ -651,7 +705,7 @@ int main(void) {
fprintf(constantsC, "\n");
fprintf(constantsC, "%s", realPointerDeclarations);
fprintf(constantsC, "\n");
fprintf(constantsC, "%s", real451PointerDeclarations);
fprintf(constantsC, "%s", real459PointerDeclarations);
fprintf(constantsC, "\n");
fprintf(constantsC, "%s", real16PointerDeclarations);
fprintf(constantsC, "\n");
......
......@@ -85,12 +85,23 @@ Out: EC=0 FI=0 SL=1 RL=LonI:"-3" RZ=Re16:"16.0" RY=Re16:"1.0" RX=Re16:"-3.0"
In: NCSD=34 SL=0 FI=0 RL=LonI:"0" RZ=Re16:"1.0" RY=Re16:"-1.786737601482363" RX=Re34:"2.054360090947453e-8"
Out: EC=0 FI=0 SL=1 RL=Re34:"2.054360090947453E-8" RZ=Re34:"3.192431174376543782196880063769" RY=Re34:"1.1497827674657217103857607276987129075472135015105120096e-8" RX=Re34:"1.7867375899845353253427828961423927230128709245278649848948799"
; x^2 + (1.0e+20 + 1)*x + 1.0e+20 = 0
;-------------------------------------------------
In: NCSD=34 SL=0 FI=0 RL=LonI:"0" RZ=Re34:"1.0" RY=Re34:"100000000000000000001.0" RX=Re34:"1e20"
Out: EC=0 FI=0 SL=1 RL=Re34:"1e20" RZ=Re34:"9999999999999999999800000000000000000001" RY=Re34:"-1.0" RX=Re34:"-1.0e20"
; 1111222233334444555566667777888886*x^2 + 1111222233334444555566667777888885*x + 277805558333611138891666944472221 = 0
;-------------------------------------------------
In: NCSD=34 SL=0 FI=0 RL=LonI:"0" RZ=Re34:"1111222233334444555566667777888886" RY=Re34:"1111222233334444555566667777888885" RX=Re34:"277805558333611138891666944472221"
Out: EC=0 FI=0 SL=1 RL=Re34:"277805558333611138891666944472221" RZ=Re34:"1" RY=Re34:"-0.5" RX=Re34:"-0.499999999999999999999999999999999100089999999999999999999999999989"
; 1111222233334444555566667777888886*x^2 + 1111222233334444555566667777888885*x + 277805558333611138891666944472221 = 0
;-------------------------------------------------
In: NCSD=34 SL=0 FI=0 RL=LonI:"0" RZ=LonI:"1111222233334444555566667777888886" RY=LonI:"1111222233334444555566667777888885" RX=LonI:"277805558333611138891666944472221"
Out: EC=0 FI=0 SL=1 RL=LonI:"277805558333611138891666944472221" RZ=Re16:"1" RY=Re16:"-0.5" RX=Re16:"-0.499999999999999999999999999999999100089999999999999999999999999989"
;=======================================================================================================================
; COMPLEX Domain
;=======================================================================================================================
......
......@@ -1013,31 +1013,31 @@ void checkRegisterType(calcRegister_t regist, char letter, uint32_t expectedData
int relativeErrorReal16(real16_t *expectedValue16, real16_t *value16, char *numberPart) {
realIc_t expectedValue, value, relativeError, numSignificantDigits;
real39_t expectedValue, value, relativeError, numSignificantDigits;
real16_t integer;
real16ToRealIc(expectedValue16, &expectedValue);
real16ToRealIc(value16, &value);
real16ToReal(expectedValue16, &expectedValue);
real16ToReal(value16, &value);
realIcSubtract(&expectedValue, &value, &relativeError);
realSubtract(&expectedValue, &value, &relativeError, &ctxtReal39);
if(!realIcIsZero(&expectedValue)) {
realIcDivide(&relativeError, &expectedValue, &relativeError);
realIcDivide(const_1, &relativeError, &numSignificantDigits);
if(!realIsZero(&expectedValue)) {
realDivide(&relativeError, &expectedValue, &relativeError, &ctxtReal39);
realDivide(const_1, &relativeError, &numSignificantDigits, &ctxtReal39);
}
else {
realIcCopy(const_1, &numSignificantDigits);
realCopy(const_1, &numSignificantDigits);
}
realIcSetPositiveSign(&numSignificantDigits);
if(!realIcIsZero(&numSignificantDigits)) {
realSetPositiveSign(&numSignificantDigits);
if(!realIsZero(&numSignificantDigits)) {
WP34S_Log10(&numSignificantDigits, &numSignificantDigits);
}
else {
realIcZero(&numSignificantDigits);
realZero(&numSignificantDigits);
}
realIcToReal16(&numSignificantDigits, &integer);
realToReal16(&numSignificantDigits, &integer);
correctSignificantDigits = real16ToInt32(&integer);
if(correctSignificantDigits <= 16) {
//printf("\nThere are only %d correct significant digits in the %s part of the value: %d are expected!\n", correctSignificantDigits, numberPart, numberOfCorrectSignificantDigitsExpected);
......@@ -1057,31 +1057,31 @@ int relativeErrorReal16(real16_t *expectedValue16, real16_t *value16, char *numb
int relativeErrorReal34(real34_t *expectedValue34, real34_t *value34, char *numberPart) {
realIc_t expectedValue, value, relativeError, numSignificantDigits;
real39_t expectedValue, value, relativeError, numSignificantDigits;
real16_t integer;
real34ToRealIc(expectedValue34, &expectedValue);
real34ToRealIc(value34, &value);
real34ToReal(expectedValue34, &expectedValue);
real34ToReal(value34, &value);
realIcSubtract(&expectedValue, &value, &relativeError);
realSubtract(&expectedValue, &value, &relativeError, &ctxtReal39);
if(!realIcIsZero(&expectedValue)) {
realIcDivide(&relativeError, &expectedValue, &relativeError);
realIcDivide(const_1, &relativeError, &numSignificantDigits);
if(!realIsZero(&expectedValue)) {
realDivide(&relativeError, &expectedValue, &relativeError, &ctxtReal39);
realDivide(const_1, &relativeError, &numSignificantDigits, &ctxtReal39);
}
else {
realIcCopy(const_1, &numSignificantDigits);
realCopy(const_1, &numSignificantDigits);
}
realIcSetPositiveSign(&numSignificantDigits);
if(!realIcIsZero(&numSignificantDigits)) {
realSetPositiveSign(&numSignificantDigits);
if(!realIsZero(&numSignificantDigits)) {
WP34S_Log10(&numSignificantDigits, &numSignificantDigits);
}
else {
realIcZero(&numSignificantDigits);
realZero(&numSignificantDigits);
}
realIcToReal16(&numSignificantDigits, &integer);
realToReal16(&numSignificantDigits, &integer);
correctSignificantDigits = real16ToInt32(&integer);
if(correctSignificantDigits <= 34) {
//printf("\nThere are only %d correct significant digits in the %s part of the value: %d are expected!\n", correctSignificantDigits, numberPart, numberOfCorrectSignificantDigitsExpected);
......
......@@ -2166,19 +2166,19 @@ void closeNim(void) {
real34Zero(REGISTER_IMAG34_DATA(REGISTER_X));
}
else {
realIc_t magnitude, theta;
real34ToRealIc(REGISTER_REAL34_DATA(REGISTER_X), &magnitude);
real34ToRealIc(REGISTER_IMAG34_DATA(REGISTER_X), &theta);
convertAngleIcFromTo(&theta, currentAngularMode, AM_RADIAN);
if(realIcCompareLessThan(&magnitude, const_0)) {
realIcSetPositiveSign(&magnitude);
realIcAdd(&theta, const_pi, &theta);
realIcDivideRemainder(&theta, const_2pi, &theta);
real39_t magnitude, theta;
real34ToReal(REGISTER_REAL34_DATA(REGISTER_X), &magnitude);
real34ToReal(REGISTER_IMAG34_DATA(REGISTER_X), &theta);
convertAngle39FromTo(&theta, currentAngularMode, AM_RADIAN);
if(real39CompareLessThan(&magnitude, const_0)) {
realSetPositiveSign(&magnitude);
realAdd(&theta, const_pi, &theta, &ctxtReal39);
realDivideRemainder(&theta, const_2pi, &theta, &ctxtReal39);
}
realIcPolarToRectangular(&magnitude, &theta, &magnitude, &theta); // theta in radian
realIcToReal34(&magnitude, REGISTER_REAL34_DATA(REGISTER_X));
realIcToReal34(&theta, REGISTER_IMAG34_DATA(REGISTER_X));
real39PolarToRectangular(&magnitude, &theta, &magnitude, &theta); // theta in radian
realToReal34(&magnitude, REGISTER_REAL34_DATA(REGISTER_X));
realToReal34(&theta, REGISTER_IMAG34_DATA(REGISTER_X));
}
}
}
......@@ -2196,19 +2196,19 @@ void closeNim(void) {
real16Zero(REGISTER_IMAG16_DATA(REGISTER_X));
}
else {
realIc_t magnitude, theta;
real16ToRealIc(REGISTER_REAL16_DATA(REGISTER_X), &magnitude);
real16ToRealIc(REGISTER_IMAG16_DATA(REGISTER_X), &theta);
convertAngleIcFromTo(&theta, currentAngularMode, AM_RADIAN);
if(realIcCompareLessThan(&magnitude, const_0)) {
realIcSetPositiveSign(&magnitude);
realIcAdd(&theta, const_pi, &theta);
realIcDivideRemainder(&theta, const_2pi, &theta);
real39_t magnitude, theta;
real16ToReal(REGISTER_REAL16_DATA(REGISTER_X), &magnitude);
real16ToReal(REGISTER_IMAG16_DATA(REGISTER_X), &theta);
convertAngle39FromTo(&theta, currentAngularMode, AM_RADIAN);
if(real39CompareLessThan(&magnitude, const_0)) {
realSetPositiveSign(&magnitude);
realAdd(&theta, const_pi, &theta, &ctxtReal39);
realDivideRemainder(&theta, const_2pi, &theta, &ctxtReal39);
}
realIcPolarToRectangular(&magnitude, &theta, &magnitude, &theta); // theta in radian
realIcToReal16(&magnitude, REGISTER_REAL16_DATA(REGISTER_X));
realIcToReal16(&theta, REGISTER_IMAG16_DATA(REGISTER_X));
real39PolarToRectangular(&magnitude, &theta, &magnitude, &theta); // theta in radian
realToReal16(&magnitude, REGISTER_REAL16_DATA(REGISTER_X));
realToReal16(&theta, REGISTER_IMAG16_DATA(REGISTER_X));
}
}
}
......
......@@ -340,20 +340,20 @@ void fnFreeFlashMemory(uint16_t unusedParamButMandatory) {
* \return void
***********************************************/
void fnBatteryVoltage(uint16_t unusedParamButMandatory) {
realIc_t value;
real39_t value;
liftStack();
#ifdef PC_BUILD
int32ToRealIc(3100, &value);
int32ToReal(3100, &value);
#endif
#ifdef DMCP_BUILD
int32ToRealIc(read_power_voltage(), &value);
int32ToReal39(read_power_voltage(), &value);
#endif
realIcDivide(&value, const_1000, &value);
realIcToReal16(&value, REGISTER_REAL16_DATA(REGISTER_X));
realDivide(&value, const_1000, &value, &ctxtReal39);
realToReal16(&value, REGISTER_REAL16_DATA(REGISTER_X));
refreshStack();
}
......
This diff is collapsed.
This diff is collapsed.
......@@ -32,7 +32,7 @@
***********************************************/
void fnConstant(const uint16_t cst) {
liftStack();
realIcToReal16((realIc_t *)constants + cst, REGISTER_REAL16_DATA(REGISTER_X));
realToReal16((real_t *)constants + cst, REGISTER_REAL16_DATA(REGISTER_X));
refreshStack();
}
......@@ -48,6 +48,6 @@ void fnConstant(const uint16_t cst) {
***********************************************/
void fnPi(uint16_t unusedParamButMandatory) {
liftStack();
realIcToReal16(const_pi, REGISTER_REAL16_DATA(REGISTER_X));
realToReal16(const_pi, REGISTER_REAL16_DATA(REGISTER_X));
refreshStack();
}
This diff is collapsed.
......@@ -28,6 +28,6 @@ void fnCvtDmsToDeg (uint16_t unusedParamButMandatory);
void fnCvtRadToDeg (uint16_t unusedParamButMandatory);
void convertAngle16FromTo (real16_t *angle16, uint32_t fromAngularMode, uint32_t toAngularMode);
void convertAngle34FromTo (real34_t *angle34, uint32_t fromAngularMode, uint32_t toAngularMode);
void convertAngleIcFromTo (realIc_t *angleIc, uint32_t fromAngularMode, uint32_t toAngularMode);
void convertAngle39FromTo (real_t *angle39, uint32_t fromAngularMode, uint32_t toAngularMode);
void checkDms16 (real16_t *angleDms);
void checkDms34 (real34_t *angleDms);
This diff is collapsed.
......@@ -1761,4 +1761,53 @@ void memoryDump2(const char *text) {
printf("\n");
// }
}
///////////////////////////////
// Stack smashing detection
void stackCheck(const unsigned char *begin, const unsigned char *end, int size, const char *where) {
int i, corrupted = 0;
for(i=0; i<size; i++) {
if(*(begin + i) != 0xaa) {
printf("Stack begin corrupted: begin[%d]=0x%02x at %s\n", i, begin[i], where);
corrupted = 1;
}
}
for(i=0; i<size; i++) {
if(*(end + i) != 0xaa) {
printf("Stack end corrupted: end[%d]=0x%02x at %s\n", i, end[i], where);
corrupted = 1;
}
}
if(corrupted) {
exit(0xBAD);
}
}
void initStackCheck(unsigned char *begin, unsigned char *end, int size) {
memset(begin, 0xaa, size);
memset(end, 0xaa, size);
}
//////////////////////////////////////////////////
// Example of stack smashing tests in a function
void stackSmashingTest(void) {
unsigned char stackEnd[10000]; // First declaration
int v1, v2, v3;
unsigned char stackBegin[10000]; // Last declaration
initStackCheck(stackBegin, stackEnd, 10000);
v1 = 1;
stackCheck(stackBegin, stackEnd, 10000, "after v1 = ...");
v2 = v1 + 1;
stackCheck(stackBegin, stackEnd, 10000, "after v2 = ...");
v3 = v2 + 2;
stackCheck(stackBegin, stackEnd, 10000, "after v3 = ...");
printf("v1=%d v2=%d v3=%d\n", v1, v2, v3);
stackCheck(stackBegin, stackEnd, 10000, "after printf(...");
}
#endif
......@@ -72,6 +72,9 @@ void debugNIM (void);
#endif
#if defined(PC_BUILD )|| defined(TESTSUITE_BUILD)
void testRegisters (const char *text);
void memoryDump2 (const char *text);
void testRegisters (const char *text);
void memoryDump2 (const char *text);
void stackCheck (const unsigned char *begin, const unsigned char *end, int size, const char *where);
void initStackCheck (unsigned char *begin, unsigned char *end, int size);
void stackSmashingTest(void);
#endif
This diff is collapsed.
......@@ -899,19 +899,19 @@ void complex34ToDisplayString(const complex34_t *complex34, char *displayString,
void complex16ToDisplayString2(const complex16_t *complex16, char *displayString) {
int16_t i=100;
real16_t real16, imag16;
realIc_t realIc, imagIc;
real39_t real39, imagIc;
if(complexMode == CM_RECTANGULAR) {
real16Copy(VARIABLE_REAL16_DATA(complex16), &real16);
real16Copy(VARIABLE_IMAG16_DATA(complex16), &imag16);
}
else if(complexMode == CM_POLAR) {
real16ToRealIc(VARIABLE_REAL16_DATA(complex16), &realIc);
real16ToRealIc(VARIABLE_IMAG16_DATA(complex16), &imagIc);
realIcRectangularToPolar(&realIc, &imagIc, &realIc, &imagIc); // imagIc in radian
convertAngleIcFromTo(&imagIc, AM_RADIAN, currentAngularMode);
realIcToReal16(&realIc, &real16);
realIcToReal16(&imagIc, &imag16);
real16ToReal(VARIABLE_REAL16_DATA(complex16), &real39);
real16ToReal(VARIABLE_IMAG16_DATA(complex16), &imagIc);
real39RectangularToPolar(&real39, &imagIc, &real39, &imagIc); // imagIc in radian
convertAngle39FromTo(&imagIc, AM_RADIAN, currentAngularMode);
realToReal16(&real39, &real16);
realToReal16(&imagIc, &imag16);
}
else {
sprintf(errorMessage, "In function complexToDisplayString2: %d is an unexpected value for complexMode!", complexMode);
......@@ -949,19 +949,19 @@ void complex16ToDisplayString2(const complex16_t *complex16, char *displayString
void complex34ToDisplayString2(const complex34_t *complex34, char *displayString) {
int16_t i=100;
real34_t real34, imag34;
realIc_t realIc, imagIc;
real39_t real39, imagIc;
if(complexMode == CM_RECTANGULAR) {
real34Copy(VARIABLE_REAL34_DATA(complex34), &real34);
real34Copy(VARIABLE_IMAG34_DATA(complex34), &imag34);
}
else if(complexMode == CM_POLAR) {
real34ToRealIc(VARIABLE_REAL34_DATA(complex34), &realIc);
real34ToRealIc(VARIABLE_IMAG34_DATA(complex34), &imagIc);
realIcRectangularToPolar(&realIc, &imagIc, &realIc, &imagIc); // imagIc in radian
convertAngleIcFromTo(&imagIc, AM_RADIAN, currentAngularMode);
realIcToReal34(&realIc, &real34);
realIcToReal34(&imagIc, &imag34);
real34ToReal(VARIABLE_REAL34_DATA(complex34), &real39);
real34ToReal(VARIABLE_IMAG34_DATA(complex34), &imagIc);
real39RectangularToPolar(&real39, &imagIc, &real39, &imagIc); // imagIc in radian
convertAngle39FromTo(&imagIc, AM_RADIAN, currentAngularMode);
realToReal34(&real39, &real34);
realToReal34(&imagIc, &imag34);
}
else {
sprintf(errorMessage, "In function complexToDisplayString2: %d is an unexpected value for complexMode!", complexMode);
......@@ -1140,34 +1140,34 @@ void angle16ToDisplayString2(const real16_t *angle16, uint8_t mode, char *displa
char degStr[27];
uint32_t m, s, fs;
int16_t sign;