# Trouble understanding rem\_pio2\_kernel

**URL:** <https://discourse.julialang.org/t/trouble-understanding-rem-pio2-kernel/15409>\
**Category:** Numerics\
**Created:** [September 24, 2018, 2:27am UTC](https://discourse.julialang.org/t/trouble-understanding-rem-pio2-kernel/15409 "2018-09-24T02:27:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [September 24, 2018, 2:27am UTC](https://discourse.julialang.org/t/trouble-understanding-rem-pio2-kernel/15409/1 "2018-09-24T02:27:58Z")

</div>

I’m having trouble understanding `Base.Math.rem_pio2_kernel`.  
Consider the following:

```julia
julia> const rempio2 = Base.Math.rem_pio2_kernel
rem_pio2_kernel (generic function with 2 methods)

julia> rempio2(0.0)
(-1, Base.Math.DoubleFloat64(1.5707963267948966, 6.12323399538461e-17))

julia> rempio2(nextfloat(0.0))
(1, Base.Math.DoubleFloat64(-1.5707963267948966, -6.12323399538461e-17))

julia> rempio2(prevfloat(0.0))
(-1, Base.Math.DoubleFloat64(1.5707963267948966, 6.12323399538461e-17))

julia> rempio2(10000.0)
(6366, Base.Math.DoubleFloat64(0.310583623688122, -5.7722118981828364e-18))

julia> rempio2(1e8)
(1, Base.Math.DoubleFloat64(0.3718988077091178, 2.2854919533097746e-17))

```

Everything seems OK until the last one; I was expecting the first entry to be `1e8 / (pi/2)` approximately.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [September 24, 2018, 2:29am UTC](https://discourse.julialang.org/t/trouble-understanding-rem-pio2-kernel/15409/2 "2018-09-24T02:29:30Z")

</div>

It’s also surprising that the first result returned is never 0.

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [September 24, 2018, 4:21pm UTC](https://discourse.julialang.org/t/trouble-understanding-rem-pio2-kernel/15409/3 "2018-09-24T16:21:31Z")

</div>

There is [some documentation](https://github.com/JuliaLang/julia/blob/8484f97844c452f15e628d4369ebc3007be0b81e/base/special/rem_pio2.jl#L210-L217), but I agree it could probably be improved.

The first value `k` has the property that

```julia
mod(k, 4) == mod(round(x / (pi/2)), 4)

```

if computed exactly.
