Skip to content

Fix -Wparentheses compiler warning - #4424

Open
d-torrance wants to merge 1 commit into
Macaulay2:developmentfrom
d-torrance:parentheses
Open

Fix -Wparentheses compiler warning#4424
d-torrance wants to merge 1 commit into
Macaulay2:developmentfrom
d-torrance:parentheses

Conversation

@d-torrance

Copy link
Copy Markdown
Member

Fixes the following:

../../../../Macaulay2/e/buffer.cpp: In member function ‘void buffer::put(cci_srcptr)’: ../../../../Macaulay2/e/buffer.cpp:175:28: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
  175 |       mpfi_is_zero(&x->re) && mpfi_is_zero(&x->im)) {
      |       ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~

AI Disclosure

No AI used

@d-torrance d-torrance added Engine Macaulay2/e build issue platform specific issues involving compiling M2, generating examples, or running tests labels Jun 8, 2026
@d-torrance
d-torrance requested review from jkyang92 and klee669 July 6, 2026 16:17
Comment thread M2/Macaulay2/e/buffer.cpp Outdated
Comment on lines +174 to +175
if (!mpfi_is_zero(&x->re) ||
mpfi_is_zero(&x->re) && mpfi_is_zero(&x->im)) {
(mpfi_is_zero(&x->re) && mpfi_is_zero(&x->im))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This check seems silly. It's !a || (a && b) which is equivalent to !a || b. The change itself is fine.

@d-torrance d-torrance Jul 10, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice catch! I've updated the commit to use this simpler logic (and also the other two complex-number-printing routines in this file)

"nonzero real part or zero" is logically equivalent to "nonzero real
part or zero imaginary part"

This fixes a previous -Wparentheses compiler warning since the
offending parenthese are no longer present.

Also use mpfr_zero_p instead of mpfr_cmp_si for simplicity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build issue platform specific issues involving compiling M2, generating examples, or running tests Engine Macaulay2/e

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants