Skip to content
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

Recode cob_decimal_pow function - Fix for #924, #925, #989 - add test cases for power operator #182

Open
wants to merge 3 commits into
base: gcos4gnucobol-3.x
Choose a base branch
from

Conversation

denishug
Copy link

No description provided.

- Fixe #924, #925, #989
- add tests case for power operator
@engboris engboris requested review from engboris and removed request for engboris September 26, 2024 17:22
@engboris
Copy link
Contributor

Hello @denishug and thank you for your contribution.

It is usually requested that contributors add an entry to ChangeLog files when modifying the source code. Here, I believe libcob/ChangeLog must be modified. There is a strict formatting (number of spaces, difference between space and tab).

Example in our PR #191 (merged)

@@ -1,4 +1,13 @@

2024-09-26 Denis Hugonnard-Roce <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in the name

* intrinsic.c (cob_decimal_pow) Correct c++ comment style to C
comment style

2024-09-25 Denis Hugonnard-Roce <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in the name

/* Fix #925 : Avoid GMPLIB CRASH */

mpf_set(cob_mpft3,cob_mpft) ;
if ( sign_nbr == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove space before condition


Process_case_0:
if (sign_nbr == 0) {
if ( sign_exp == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove space before condition

if (sign == 0) {
/* 0 ^ 0 */
cob_set_exception (COB_EC_SIZE_EXPONENTIATION);
sign_nbr = mpz_sgn(pd1->value);
Copy link
Contributor

@engboris engboris Oct 21, 2024

Choose a reason for hiding this comment

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

In order to strictly follow GnuCOBOL's coding style, a space character should be inserted before function calls. And it shouldn't occur before the ; character.

For reference, don't hesitate to look at how the code is written elsewhere in GnuCOBOL's source.

Copy link
Collaborator

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

Thanks for this nice piece of work. I think the Changelog entries could be improved and there are some code parts + formatting, but overall quite good!

Copy link
Collaborator

Choose a reason for hiding this comment

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

As those changes are all below libcob, they don't belong here - just revert that file, moving the better text there.
Since quite some time we only Changlog the testsuite if there are "bigger" changes (moving tests around or adding new internal features), so you can drop that part.

Comment on lines +4 to +7
* intrinsic.c (cob_decimal_pow) Correct c++ comment style to C
comment style

2024-09-25 Denis Hugonnard-Roce <[email protected]>
Copy link
Collaborator

Choose a reason for hiding this comment

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

as this is an update to a not-yet-checked in change, just edit the date for the original change and drop the update

AT_CHECK([$COMPILE prog.cob], [0], [], [])
AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], [])
AT_CLEANUP

Copy link
Collaborator

Choose a reason for hiding this comment

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

minor beautify: please separate test cases with a double empty line - also above

AT_CLEANUP

AT_SETUP([Power size error and limits cases 2])
AT_KEYWORDS([POWER])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Words that are in AT_SETUP are automatically added to the keyword list. Replacing it with the main statement - here COMPUTE - would be useful (also applies above).

Copy link
Collaborator

Choose a reason for hiding this comment

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

please add an m4 comment about which tests are for which bug report - this provides more context and is also useful in the future

break;

case 0:
goto Process_case_0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is a single case for this - please inline instead of using goto

mpz_set_ui (pd1->value, 1UL);
pd1->scale = 0;
return;
goto Compute_Power;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please reorder that case to have zero first, this can then return while the fall-through of 1/-1 is easier to follow and we don't need the Compute_Power label any more

Comment on lines +3170 to +3176
sign_nbr = mpz_sgn(pd1->value);
sign_exp = mpz_sgn(pd2->value);

power_case = sign_nbr * sign_exp;

cob_trim_decimal(pd2);
cob_trim_decimal(pd1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please reformat to use a space before the parenthesis (also applies to other places)?

Comment on lines +3170 to +3173
sign_nbr = mpz_sgn(pd1->value);
sign_exp = mpz_sgn(pd2->value);

power_case = sign_nbr * sign_exp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those are all "cheap" and don't break for NAN scale - please const those three variables directly at the start of the function.

if (mpz_sgn (pd2->value) == -1
&& mpz_fits_slong_p (pd2->value)) {

if (mpz_sgn (pd2->value) == -1 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't that sign_exp now?

@engboris engboris changed the title Recode cob_decimal_pow function - Fixe #924, #925, #989 - add tests case for power operator Recode cob_decimal_pow function - Fix #924, #925, #989 - add tests case for power operator Oct 21, 2024
@engboris engboris changed the title Recode cob_decimal_pow function - Fix #924, #925, #989 - add tests case for power operator Recode cob_decimal_pow function - Fix for #924, #925, #989 - add tests case for power operator Oct 21, 2024
@engboris engboris changed the title Recode cob_decimal_pow function - Fix for #924, #925, #989 - add tests case for power operator Recode cob_decimal_pow function - Fix for #924, #925, #989 - add test cases for power operator Oct 21, 2024
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.

4 participants