Skip to content

Base: slight simplification in int.jl #50654

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

Closed
wants to merge 1 commit into from

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Jul 24, 2023

Use ~, zero and shifts to simplify the definitions of typemin and typemax.

Use `~`, `zero` and shifts to simplify the definitions of `typemin` and
`typemax`.
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

This seems likely unnecessarily harder for the compiler to constant evaluate, and incorrectly switches the position / ordering of Union and Type

@nsajko
Copy link
Contributor Author

nsajko commented Jul 24, 2023

Why is "harder for the compiler to constant evaluate" a problem? Naively, I'd think that would only be a problem the first time Julia compiles the relevant method?

incorrectly switches the position / ordering of Union and Type

What does this mean? Does it refer to the fact that, with this commit, methods like typemin(::Union{Int8,Int16}) exist, but result in a MethodError when called? If that's an issue, I think I could fix it using traits.

@vtjnash
Copy link
Member

vtjnash commented Jul 24, 2023

Union{map(t -> Type{t}, BitSigned_types)...} is also valid for that, but still doesn't seem like a simplification

@nsajko
Copy link
Contributor Author

nsajko commented Jul 24, 2023

Why is typemin accepting calls like typemin(Union{Int8,Int16}) a problem in the first place? Seems like where {T<:Union{...}} is a common pattern otherwise in Julia.

I'm asking because I'm interested in somewhat similar but more significant changes elsewhere in Base.

@nsajko nsajko closed this Feb 11, 2024
@nsajko nsajko deleted the int_complement branch February 11, 2024 19:05
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.

2 participants