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

bug with min and max function #6

Open
vrossum opened this issue Feb 12, 2023 · 3 comments
Open

bug with min and max function #6

vrossum opened this issue Feb 12, 2023 · 3 comments
Labels

Comments

@vrossum
Copy link

vrossum commented Feb 12, 2023

Hi
I see a weird bug with the min and max functions.
y=min(x,1) is fine
but
y=min(1,x) produces an error.
It seems that any expressions with x need to be in the first argument.

If this is really an error and hard to fix, a note in documentation might help.

As an aside, xmgrace works in both cases, but uses the function 'minof'

@mlund mlund added the bug label Nov 14, 2023
@mlund
Copy link
Owner

mlund commented Nov 14, 2023

Hmm, yes that doesn't sound right. What error do you get? We have generally only fixed issues that allow's xmgr to build on newer systems, but it would be nice to correct that behavior.

@mlund
Copy link
Owner

mlund commented Nov 14, 2023

I'm not sure if this is the code in question, but here the first argument must be an array of values, while the second argument is an integer defining the number of elements.

/*
* compute the mins and maxes of a vector x
*/
double vmin(double *x, int n)
{
int i;
double xmin;
if (n <= 0) {
return 0.0;
}
xmin = x[0];
for (i = 1; i < n; i++) {
if (x[i] < xmin) {
xmin = x[i];
}
}
return xmin;
}

Inspecting src/pars.c, MIN() does seem to ignore the second argument (1 in your case) and call vmin() which returns the minimum value in the vector. This is in conflict with the manual. Can you confirm this behavior?

@vrossum
Copy link
Author

vrossum commented Nov 14, 2023

Hi
Thank for taking a look.
y=max(y,2) works as expected (the 2nd arg is not ignored).
max(2,y) throws the error (error in do_compute)

The ideal behaviour would be:

  • when a is a vector and b is a single number
    c= max(a,b) should return c_i= max(a_i,b)
  • when both vectors
    c_i = max(a_i,b_i)
  • and, max should be a symmetric function.

The vmin function, minimum of first n elements seems a bit odd to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants