Giter Club home page Giter Club logo

Comments (17)

kgryte avatar kgryte commented on June 11, 2024 1

Yes, but we should not just rely on what the current behavior is in stdlib, as the current behavior could be wrong. In this case, we need to consult the specification to ensure that our current atan behavior adheres to IEEE 754 semantics.

In this case, it does. Which just means that our current atanf implementation does not handle signed zero correctly.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024 1

When you make patch, can you also add corresponding tests to atanf?

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024 1

Great, I'll follow that. Thanks for clearing this out.
This can be a nice example for why we shouldn't rely on just one source, like cephes.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024 1

Indeed! And the importance of tests! We are apparently missing corresponding tests in atan, as well. You can include those in your patch.

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

I'd like to work on this.

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

Hey @kgryte, while implementing this, I got to know that, since we require atanf for this, and upon passing -infinity to acotf, or -0 to atanf, our atanf returns 0, instead of -0. This applies for both C and JavaScript implementations of atanf.

This leads to the failure of one particular test case, which checks if the function returns "-0" if provided "-infinity".

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

In the case of current acot, this problem doesn't arise, but it does come up in case of acotf.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024

Which behavior is the correct behavior?

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

The correct behavior is that of acot, i.e, it returns -0 when provided -infinity.

Applying the same implementation for acotf, this fails.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024

The question is more fundamental. Should atan distinguish between signed zeros? This is a mathematical question.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024

It's possible, e.g., that the tests for acot are incorrect, but this gets back to what the behavior of atan should be.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024

We get our answer from http://www.dsc.ufcg.edu.br/~cnum/modulos/Modulo2/IEEE754_2008.pdf

For the functions expm1, exp2m1, exp10m1, logp1, log2p1, log10p1, sin, tan, sinPi, atanPi, asin, atan, sinh, tanh, asinh, and atanh, f (+0) is +0 and f (−0) is −0 with no exception.

Meaning, atanf is incorrect here.

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

When I checked logging the values with atan, it returns:

atan( -0 ) = -0
atan( +0 ) = 0

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

Yes, and also, upon doing the same for atanf, it gives 0 in both cases.

We might need to modify our atanf implementation.

from stdlib.

kgryte avatar kgryte commented on June 11, 2024

The reason it doesn't is pretty straightforward. We just need to make a small modification to atanf which we can observe in atan. Namely, the following

should be modified to

if ( isnanf( x ) ) {
+ if ( isnanf( x ) || x === 0.0 ) {
+    return x;

This is a bug in the original Cephes implementation. You'll want to fix in both our JS and C atanf implementations.

from stdlib.

gunjjoshi avatar gunjjoshi commented on June 11, 2024

Sure, I'll do it. Should this be added in the same PR as that of acotf, or a seperate one ?

from stdlib.

kgryte avatar kgryte commented on June 11, 2024

I suggest making a quick patch in a separate PR to keep things clean.

from stdlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.