JuliaMath / JuliaMath/Quadmath.jl
`rem(::Float128, ::Float128)` uses round-to-nearest instead of truncated
- Dominant language
- Julia
- Stars
- 44
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
`Base.rem` for `Float128` uses libquadmath's `remainderq`:
https://github.com/JuliaMath/Quadmath.jl/blob/9f739ce92d08c24042a00c095188e83a2e1b88d3/src/Quadmath.jl#L330-L331
Which implements round-to-nearest quotient. Julia's `rem` uses truncated division, round-to-zero.
This leads to inconsistencies in computations that use `Base.rem`, such as `sind`, `cosd`, `tand`.
## MWE
```julia
julia> using Quadmath
julia> rem(Float128(7.5), Float128(2))
-0.5 # expected 1.5
julia> rem(7.5, 2.0) # Float64 reference
1.5
julia> rem(Float128(200), Float128(360))
-160 # expected 200.0
```
## Fix
Call `fmodq` instead of `remainderq`.
If we want to also support the current behaviour, `remainderq` corresponds to`Base.rem(x, y, RoundNearest)`, which could be added as a separate method.
Contributor guide
No contributing guide indexed for this repository
Research direction
Open src/Quadmath.jl around lines 330-331 and inspect how Base.rem for Float128 calls libquadmath. Change the behavior so the MWE returns the truncated-division results shown in the issue, then verify the rem examples and the sind, cosd, and tand computations mentioned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100