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

Remove inner constructor for ExactReal #660

Merged
merged 4 commits into from
May 29, 2024
Merged

Conversation

dpsanders
Copy link
Member

@dpsanders dpsanders commented May 28, 2024

This was preventing

ExactReal{Int64}(3)

which should be allowed.

@OlivierHnt
Copy link
Member

I think this was done on purpose to avoid silent errors, e.g.

julia> ExactReal{Float64}(1//3)
ExactReal{Float64}(0.3333333333333333)

@Kolaru
Copy link
Collaborator

Kolaru commented May 28, 2024

I think David's example should indeed be allowed, and Olivier's forbidden.

To make it so, we can add a second inner constructor:

struct ExactReal{T<:Real} <: Real
    value :: T

    ExactReal{T}(value::T) where {T<:Real} = new{T}(value)
    ExactReal(value::T) where {T<:Real} = new{T}(value)
end

@dpsanders
Copy link
Member Author

Thanks @Kolaru, I added that inner constructor instead.

@Kolaru
Copy link
Collaborator

Kolaru commented May 29, 2024

Quickly added simple tests, and LGTM, thanks :)

@Kolaru Kolaru merged commit 0bb1d9b into master May 29, 2024
32 checks passed
@OlivierHnt OlivierHnt deleted the dps-exact-real-constructor branch June 2, 2024 08:27
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.

3 participants