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

add inttype, floattype like uinttype #36526

Merged
merged 1 commit into from
Apr 24, 2021
Merged

add inttype, floattype like uinttype #36526

merged 1 commit into from
Apr 24, 2021

Conversation

JeffreySarnoff
Copy link
Contributor

uinttype is an unexported function that maps IEEEFloat types to their bitwidth-matched Unsigned types.
This PR adds inttype and floattype (also unexported). inttype maps IEEEFloats to bitwidth-matched Signed types and floattype maps uinttype(T), inttype(T) where {T<:IEEEFloat} to the bitwidth-matched IEEEFloat type.

I use these functions often -- less elegantly defined (overloading reinterpret or rem). As they are unexported, I did not add NEWS. Since there are no tests for uinttype, I did not add tests .. although I am happy to do so for all three functions should that be preferred.

@kimikage
Copy link
Contributor

kimikage commented Jul 3, 2020

FixedPointNumbers defines and exports floattype, which is used by packages related to graphic and image processing.
It's weird that the floattype is defined in FixedPointNumbers, and it's not bad to define it in Base. However, the floattype in FixedPointNumbers is not consistent with Base.float due to performance concerns (cf. JuliaMath/FixedPointNumbers.jl#127).

Of course, this is just the problem in a specific ecosystem.

@kimikage
Copy link
Contributor

cf. #30445

@oscardssmith
Copy link
Member

bump. I think this would be good to have (at least internally).

@kimikage
Copy link
Contributor

I agree that it is not a problem because they are not exported, but I do not think it is good practice to use functions that are not exported.

BTW, we can find inttype in a surprising place. 😄

julia> Base.Threads.inttype(Float32)
Int32

The root of the problem is that whether you associate the names inttype or floatype with reinterpretation or conversion depends on the context and personal mindset.

@musm
Copy link
Contributor

musm commented Apr 23, 2021

I've also needed these in the past. Since they're internal I find these definitions relatively harmless and are more for convenience.

Sans objections I plan on merging this in a day.

@musm musm merged commit 659bc12 into JuliaLang:master Apr 24, 2021
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
jarlebring pushed a commit to jarlebring/julia that referenced this pull request May 4, 2021
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
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.

4 participants