Skip to content
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

Use Base.Math.rem_pio2_kernel for quadrant on Julia 0.7 #119

Closed
dpsanders opened this issue Apr 11, 2018 · 6 comments
Closed

Use Base.Math.rem_pio2_kernel for quadrant on Julia 0.7 #119

dpsanders opened this issue Apr 11, 2018 · 6 comments

Comments

@dpsanders
Copy link
Member

In Julia 0.7 we can use Base.Math.rem_pio2_kernel for the quadrant calculation for trig functions, especially tan.

(Thanks to Simon Byrne for the tip.)

@dpsanders dpsanders changed the title Use Base.Math.rem_pio2_kernel for quadrant calculation Use Base.Math.rem_pio2_kernel for quadrant on Julia 0.7 Apr 11, 2018
@lbenet
Copy link
Member

lbenet commented Apr 12, 2018

I was checking the way mod2pi is coded in Base (because find_quadrants is essentially a discrete version of mod_pi_half function; see #117). It turns out that mod2pi(x) is a call to rem2pi(x, RoundDown); I wonder if this can be a work around that.

@dpsanders
Copy link
Member Author

I tried that, but it's not good enough (or, at least, I couldn't get it to work) -- we actually need a rem_half_pi function, which is what the function in #119 provides.

@lbenet
Copy link
Member

lbenet commented Apr 12, 2018

For floats, see what ieee754_rem_pio2; it is in Base.Math. I don't know how is rem2pi coded for BigFloats, or whether there is something like ieee754_rem_pio2 for them.

@dpsanders
Copy link
Member Author

dpsanders commented Apr 12, 2018

rem2pi just calls an MPFR function:

@edit rem(big"0.1", 2*BigFloat(pi), RoundNearest)

You're right that ieee754_rem_pio2 would be the correct function, but:

julia> @btime Base.Math.ieee754_rem_pio2(3.1)
  39.199 ns (2 allocations: 128 bytes)
(2, [-0.0415927, 2.43541e-18])

whereas on 0.7:

julia> @btime Base.Math.rem_pio2_kernel(3.1)
  1.648 ns (0 allocations: 0 bytes)
(2, Base.Math.DoubleFloat64(-0.04159265358979315, 2.4354103626379128e-18))

!!

@dpsanders
Copy link
Member Author

Fixed by #235.

@dpsanders
Copy link
Member Author

Finally rem2pi was used.

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

No branches or pull requests

2 participants