FEniCS / ffcx

Next generation FEniCS Form Compiler for finite element forms
https://fenicsproject.org
Other
149 stars 40 forks source link

Use correct C `math.h` functions for `complex` #578

Closed garth-wells closed 1 year ago

garth-wells commented 1 year ago

For float, FFCx generates code that uses fabs but it should use fabsf for floats. Same is likely for other math functions.

Need to check and use correct functions.

chrisrichardson commented 1 year ago

I don't find it is wrong. I tried ffcx --scalar_type=float Poisson.py and it contains fabsf. Maybe it depends how it is called - from Python I guess it may not be passing scalar_type properly? Can you provide an example?

garth-wells commented 1 year ago

I don't find it is wrong. I tried ffcx --scalar_type=float Poisson.py and it contains fabsf. Maybe it depends how it is called - from Python I guess it may not be passing scalar_type properly? Can you provide an example?

I'll dig out the test that generated the compiler warnings.

chrisrichardson commented 1 year ago

I think I have found the problem here - not so much with float but with complex - the code generator assumes that all math functions should be appropriate for the scalar type (e.g. complex), but the geometry is never complex, so using e.g. cabs() is wrong, and generates a compiler warning. I think this could be fixed e.g. with a "typing" system for CNodes Symbol but that will require quite a bit of work.

chrisrichardson commented 1 year ago

Fixed in #594