Skip to content

Conversation

@oscardssmith
Copy link
Contributor

as requested by @c05 on slack. This has 15 ULP for Float64, and 5 ULP for Float32.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Can you add tests and update the docs? Probably should also add a ChainRules definition.

src/basicfuns.jl Outdated
The implementation ensures `logabstanh(-x) = logabstanh(x)`.
"""
function logabstanh(x::Real)
return log1p(-2/((exp(2abs(x))+1)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As indicated by the special cases close to 0 for Float32 and Float64, maybe a safer default would be

Suggested change
return log1p(-2/((exp(2abs(x))+1)))
return log(abs(tanh(x)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the version I wrote stays more accurate overall but I'll do a test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to do such an analysis? You can't realistically test any subtype of Real.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for any AbstractFloat log(tanh(x)) will be inaccurate for large x since tanh(x) will be very close to 1.

oscardssmith and others added 4 commits November 16, 2024 09:36
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
@3f6a
Copy link

3f6a commented Nov 25, 2024

Something missing here? Or can this be merged ?

@devmotion
Copy link
Member

Can you add tests and update the docs? Probably should also add a ChainRules definition.

@oscardssmith
Copy link
Contributor Author

Should I re-open and rebase to add Float32 and Float64 fast-paths?

@nsajko
Copy link
Contributor

nsajko commented Aug 18, 2025

It might be simpler to just revert 39127b6 instead of rebasing. For a start I mean.

@tpapp
Copy link
Collaborator

tpapp commented Aug 18, 2025

@oscardssmith: choose whatever is most convenient for you, but having these methods would be very welcome. The new testing framework should be sufficient for tests.

@oscardssmith
Copy link
Contributor Author

can you reopen? I seem to not have permission to.

@tpapp
Copy link
Collaborator

tpapp commented Aug 18, 2025

Unfortunately I am unable, Github says "that these commits are already merged."

@nsajko
Copy link
Contributor

nsajko commented Aug 18, 2025

Yeah, all of them are part of the merged PR.

@oscardssmith
Copy link
Contributor Author

ah. Will re-create then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants