jmert / AssociatedLegendrePolynomials.jl

A library for calculating the Associated Legendre polynomials
https://jmert.github.io/AssociatedLegendrePolynomials.jl/
MIT License
20 stars 2 forks source link

Replace abuse of at-fastmath(sqrt) with an unchecked_sqrt implementation #22

Closed jmert closed 2 years ago

jmert commented 4 years ago

Using @fastmath(sqrt) as a way to get a square root calculation without the domain (x < 0) check is a bit of an abuse of the macro. Instead, there should be an unchecked_sqrt function that skips the domain check without also annotating code with fast-math flags since that can introduce unwanted semantics.

A constraint is that we don't want to break the genericness of the implementation, so a reasonable fallback path needs to be indentified. For instance, right now the method called is actually Base.FastMath.sqrt_fast which may already have useful overloads from other number-type packages that we don't necessarily want to lose. Therefore some research across the package ecosystem is probably warranted.

More context in a Julia Discourse post and a related LLVM bug report