Skip to content

Base: slight simplification in int.jl#50654

Closed
nsajko wants to merge 1 commit intoJuliaLang:masterfrom
nsajko:int_complement
Closed

Base: slight simplification in int.jl#50654
nsajko wants to merge 1 commit intoJuliaLang:masterfrom
nsajko:int_complement

Conversation

@nsajko
Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
Member 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