-
Notifications
You must be signed in to change notification settings - Fork 41
Bug fix for BIN and changes to return values of POLYCENT and POLYAREA #173
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b09d795
bug fix for BIN and changes to return values of POLYCENT and POLYAREA
Joe7M 5f4cbda
Implementation of MEDIAN() to calculate the median of a data sample i…
Joe7M 2721e2a
Small changes for kwBIN and STATMEDIAN.
Joe7M 4e66025
Update BIN and STATMEDIAN
Joe7M File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ static char *date_m3_table[] = TABLE_MONTH_3C; | |
| static char *date_mN_table[] = TABLE_MONTH_FULL; | ||
|
|
||
| #define BUF_LEN 64 | ||
| #define BIN_LEN 32 // Number of max bits (digits) kwBIN creates | ||
|
|
||
| /* | ||
| */ | ||
|
|
@@ -957,19 +958,33 @@ void cmd_str1(long funcCode, var_t *arg, var_t *r) { | |
| // | ||
| case kwBIN: | ||
| l = v_getint(arg); | ||
| IF_ERR_RETURN; | ||
| tb = malloc(33); | ||
| memset(tb, 0, 33); | ||
| for (int i = 0; i < 32; i++) { | ||
| IF_ERR_RETURN; | ||
|
|
||
| if (l == 0) { | ||
| v_createstr(r, "0"); | ||
| break; | ||
| } | ||
|
|
||
| tb = malloc(BIN_LEN + 1); | ||
| memset(tb, 0, BIN_LEN + 1); | ||
|
|
||
| for (int i = 0; i < BIN_LEN; i++) { | ||
| if (l & (1 << i)) { | ||
| tb[31 - i] = '1'; | ||
| tb[BIN_LEN - 1 - i] = '1'; | ||
| } else { | ||
| tb[31 - i] = '0'; | ||
| tb[BIN_LEN - 1 - i] = '0'; | ||
| } | ||
| } | ||
|
|
||
| // remove preceding zeros | ||
| p = tb; | ||
| while (*p == '0') { | ||
| p++; | ||
| } | ||
|
|
||
| r->v.p.ptr = tb; | ||
| r->v.p.length = strlen(r->v.p.ptr) + 1; | ||
| v_createstr(r, p); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to call |
||
| free(tb); | ||
|
|
||
| break; | ||
| case kwHEX: | ||
| // | ||
|
|
@@ -2307,7 +2322,7 @@ void cmd_genfunc(long funcCode, var_t *r) { | |
| for (int i = 0; i < count - 1; i++) { | ||
| r->v.n = r->v.n + (poly[i].x - poly[i + 1].x) * (poly[i].y + poly[i + 1].y); | ||
| } | ||
| r->v.n = fabs(r->v.n / 2); | ||
| r->v.n = r->v.n / 2; | ||
|
|
||
| free(poly); | ||
| } | ||
|
|
@@ -2327,17 +2342,21 @@ void cmd_genfunc(long funcCode, var_t *r) { | |
| IF_ERR_RETURN; | ||
|
|
||
| err = geo_polycentroid(poly, count, &x, &y, &area); | ||
| v_toarray1(r, 2); | ||
| v_setreal(v_elem(r, 0), x); | ||
| v_setreal(v_elem(r, 1), y); | ||
|
|
||
| if (err == 1) { | ||
| rt_raise(ERR_WRONG_POLY); | ||
| } | ||
| if (err == 2) { | ||
| rt_raise(ERR_CENTROID); | ||
| } | ||
| // return empty array insead of "rt_raise(ERR_CENTROID);" | ||
| v_toarray1(r, 0); | ||
| free(poly); | ||
| break; | ||
| } | ||
|
|
||
| v_toarray1(r, 2); | ||
| v_setreal(v_elem(r, 0), x); | ||
| v_setreal(v_elem(r, 1), y); | ||
|
|
||
| free(poly); | ||
| } | ||
| break; | ||
|
|
@@ -2600,6 +2619,7 @@ void cmd_genfunc(long funcCode, var_t *r) { | |
| // | ||
| // | ||
| case kwSTATMEANDEV: | ||
| case kwSTATMEDIAN: | ||
| case kwSTATSTD: | ||
| case kwSTATSPREADS: | ||
| case kwSTATSPREADP: | ||
|
|
@@ -2670,6 +2690,9 @@ void cmd_genfunc(long funcCode, var_t *r) { | |
| case kwSTATMEANDEV: | ||
| r->v.n = statmeandev(dar, tcount); | ||
| break; | ||
| case kwSTATMEDIAN: | ||
| r->v.n = statmedian(dar, tcount); | ||
| break; | ||
| case kwSTATSTD: | ||
| r->v.n = statstd(dar, tcount); | ||
| break; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add some more testing for BIN. Something like this could be added to strings.bas