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

Adding stop-gaps for trenscendental functions, Base.round, Base.rand and Base.:^ #14

Merged
merged 2 commits into from Jan 3, 2021

Conversation

lrnv
Copy link
Contributor

@lrnv lrnv commented Dec 28, 2020

Should close issues #7 and #8

Sorry for the delay, i took chritsmas vacations ;)

I did some testing but it's not perfect. Maybe we should write tests to be sure everything works ?

@dzhang314
Copy link
Owner

Hey @lrnv , no worries! As you can see, I've been taking a bit of a break recently too. :)

I had a look at your code, and there is an issue I would like to point out. The stop-gap implementation you have here does not consider the precision of BigFloat when performing the conversions. In Julia, the default precision of BigFloat is 256 bits, which is not enough for Float64x5, ..., Float64x8. Therefore, instead of this:

Base.exp(x::MF{T,N}) where {T,N} = MF{T,N}(exp(BigFloat(x)))

We need something like this:

Base.exp(x::MF{T,N}) where {T,N} = setprecision(BigFloat, N * precision(T) + (N - 1)) do
    MF{T,N}(exp(BigFloat(x)))
end

In practice I would probably use something like N * precision(T) + (N - 1) + 20 instead, just to have a bit of safety margin. I will go ahead, accept this PR, and make this change myself.

@dzhang314 dzhang314 merged commit 2f99274 into dzhang314:master Jan 3, 2021
@dzhang314
Copy link
Owner

After some more thought, I've decided that I don't want to expose these stop-gaps by default. The issue is that a new user may write, say, asinh(Float64x4(2.3)), observe that it is quite slow, and think something is wrong with MultiFloats.jl, when in reality it is asinh(::BigFloat) that is the culprit. I would like to strike a compromise where the stop-gap is available if you need it, but you have to consciously opt-in to using something that has suboptimal performance.

What I'll do is have asinh(::MultiFloat) throw the following error by default:

asinh(MultiFloat) is not yet implemented. You can call MultiFloats.use_bigfloat_transcendentals()
for a temporary workaround, but this will not be as fast as a pure-MultiFloat implementation.

As the error message indicates, you can enable the stop-gap by calling MultiFloats.use_bigfloat_transcendentals() immediately after importing MultiFloats.jl.

@lrnv
Copy link
Contributor Author

lrnv commented Jan 4, 2021

This is perfect for me. Thanks a lot !

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

Successfully merging this pull request may close these issues.

None yet

2 participants