-
Notifications
You must be signed in to change notification settings - Fork 414
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
Problem with Absolute Value of Floating Point PARAM #24119
Comments
Technically there is a fourth simple operation which is the assignment to the absolute value of one source of the negative (or sign) bit of a second source, nominally called copysign(). But I did not want to complicate the discussion. |
@damianmoz - thanks for filing the issue. I've created PR #24127 to add the missing param overloads for real/imag |
Not urgent. I figure that param complex(w) is a lot more difficult and will take even longer. It was more that I noticed the issue across the break and I figured that Chapel needed this completeness of features across all of its floating point and integral types eventually. |
@damianmoz / @mppf: Is this issue now complete other than the abs on param complex returning complex, now spun off to #24125? If so, is it OK if I close this one in favor of that one? |
Yes (as far as I can tell) to the first question and Yes to the second question. |
For issue #24119. Resolves #24125. This PR adds overloads to AutoMath to implement `param` versions of: * `abs` for all numeric types * `sqrt` for floating-point types. Additionally, while testing, I realized that `complex.re` and `complex.im` did not have `param` returning versions, so this PR also adds such param-returning versions to ChapelBase. To implement these, I: * added `PRIM_SQRT` and `PRIM_ABS`. For now, these are just used for computing these functions on `param`s and they will cause the compiler to error out one makes it to code-generation time. * implemented folding for `PRIM_ABS`, `PRIM_SQRT`, `PRIM_GET_REAL`, and `PRIM_GET_IMAG` in num.cpp * enabled `postFoldPrimop` to fold `PRIM_ABS`, `PRIM_SQRT`, `PRIM_GET_REAL`, and `PRIM_GET_IMAG` This PR also updates the spec description of `complex` to make it clearer. While there, it removes `proc complex.bits` from the spec, since this method does not exist other than in the spec. Reviewed by @DanilaFe - thanks! - [x] full comm=none testing Future Work: * #22809 * in particular, resolve two confusing errors I posted as comments based on work on this PR * update the dyno resolver to assert `PRIM_ABS`, `PRIM_SQRT` are only used on `param` values * update the dyno resolver to implement `PRIM_GET_REAL` and `PRIM_GET_IMAG` on `param` values
Beyond the 5 basic mathematical operations, addition, subtraction, multiplication, division and square root which can affect IEEE 754 exceptions, there are also simple operations which never raise an IEEE 754 exception
In Chapel, the first two are implemented for params. Because Chapel nominally implements the last with a routine from the system matrhematical library, it cannot return the absolute value of a param as a param. One can argue that this is an oversight because the compiler can figure that out for itself for a param argument and when the argument is a const the optimizer will most likely on modern hardware discard any reference to the implied routine and implement the operation as a single machine instruction.
I am not suggesting that this implementation is the way to go. It just provides a workaround.
The text was updated successfully, but these errors were encountered: