Skip to content

Conversation

@Joe7M
Copy link
Contributor

@Joe7M Joe7M commented Dec 5, 2022

Hi Chris,

four small things:

  1. BIN: preceding zeros will be removed now: PRINT BIN(12) -> Old 00000000000000001100 -> new 1100.
  2. POLYCENT will return an empty array if Polygon has zero area.
  3. POLYAREA will return sign of area to distinguish between left and right handed polygon.
  4. Implementation of MEDIAN for statistics calculations

Best regards, Joerg


qsort(e, count, sizeof(var_num_t), median_compare);

if (count % 2 == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add curley braces around the single lines?
also indent with 2 spaces :)

//
// compare function for median calculation
//
int median_compare (const void * a, const void * b) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the space between the function name and "("

IF_ERR_RETURN;

if (l == 0) {
r->v.p.ptr = (char *)malloc(2);
Copy link
Contributor

@chrisws chrisws Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines should be replaced with a call to v_createstr(r, "0")


tb = malloc(33);
memset(tb, 0, 33);
memset(tb, 0, 33);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please replace 33 with a constant (#define is okay) ?

}

r->v.p.ptr = tb;
r->v.p.ptr = (char *)malloc(strlen(p) + 1);
Copy link
Contributor

@chrisws chrisws Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be replaced with a call to v_createstr

BCS:catsanddogs
BGETC:
BIN:00000000000000000000000000001100
BIN:1100
Copy link
Contributor

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

bin_test=[[,], [0, "0"], [7, "111"], [14, "1110"], [15, "1111"]]
for t in bin_test
  if (t[1] != bin(t[0])) then throw "err:" + str(t) + " <> " + bin(t[0])
next  

@Joe7M
Copy link
Contributor Author

Joe7M commented Dec 28, 2022

Hi Chris, I made a new commit with the changes you suggested. Best regards, Joerg

p++;
}

v_createstr(r, p);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to call free(tb); before the break; line to avoid a memory leak


if (count % 2 == 0) {
return (e[count/2] + e[count/2 - 1]) / 2;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to be a pain, but could you pls reformat the else line to be on the same line as the closing brace, ie:

} else {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff - thanks for the changes

@Joe7M
Copy link
Contributor Author

Joe7M commented Dec 28, 2022

No problem. Here the changes. Most probably my last action this year. I wish you a happy new year.

@chrisws chrisws self-requested a review December 28, 2022 23:27
@chrisws chrisws merged commit 7b2d0a8 into smallbasic:master Dec 28, 2022
@chrisws
Copy link
Contributor

chrisws commented Dec 28, 2022

No worries - happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants