Skip to content

Expose more math functions in math.h#2364

Open
romanc wants to merge 4 commits into
spcl:mainfrom
romanc:romanc/math-functions
Open

Expose more math functions in math.h#2364
romanc wants to merge 4 commits into
spcl:mainfrom
romanc:romanc/math-functions

Conversation

@romanc
Copy link
Copy Markdown
Contributor

@romanc romanc commented May 11, 2026

Description

dace/math.h re-exposes a couple of math functions from cmath, e.g. std::sin(x), which has overloads for e.g. float and double. Some functions, e.g. asin(x), were not exposed in this way. This leads to precision issues when asin(x) is called with a float because in the generated code, asin will be mapped to the C version, which is only defined for doubles. There is thus an implicit cast happening of the argument and the computation is done in double precision. Worse, the return type is always a double, which will force the rest of the calculation to be up-casted to double precision if asin() is used in an expression.

@romanc romanc marked this pull request as ready for review May 11, 2026 13:26
Copy link
Copy Markdown
Contributor

@alexnick83 alexnick83 left a comment

Choose a reason for hiding this comment

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

This looks fine. I would add a test that demonstrates the issue described in the PR (up/downcasting of data) and confirms that it is now resolved. I guess just one test for, e.g., asin would be enough.

@romanc
Copy link
Copy Markdown
Contributor Author

romanc commented May 11, 2026

Make sense, I'll add something tomorrow. I think I can build upon compare_numpy_output().

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