-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make LinSpace generic #18777
Merged
Merged
Make LinSpace generic #18777
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -752,6 +752,29 @@ fpinttype(::Type{Float16}) = UInt16 | |
# maximum float exponent without bias | ||
@pure exponent_raw_max{T<:AbstractFloat}(::Type{T}) = Int(exponent_mask(T) >> significand_bits(T)) | ||
|
||
## TwicePrecision utilities | ||
# The numeric constants are half the number of bits in the mantissa | ||
for (F, T, n) in ((Float16, UInt16, 5), (Float32, UInt32, 12), (Float64, UInt64, 26)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the significance of these |
||
@eval begin | ||
function truncbits(x::$F, nb) | ||
@_inline_meta | ||
truncmask(x, typemax($T) << nb) | ||
end | ||
function truncmask(x::$F, mask) | ||
@_inline_meta | ||
reinterpret($F, mask & reinterpret($T, x)) | ||
end | ||
function splitprec(x::$F) | ||
@_inline_meta | ||
hi = truncmask(x, typemax($T) << $n) | ||
hi, x-hi | ||
end | ||
end | ||
end | ||
|
||
truncbits(x, nb) = x | ||
truncmask(x, mask) = x | ||
|
||
## Array operations on floating point numbers ## | ||
|
||
float{T<:AbstractFloat}(A::AbstractArray{T}) = A | ||
|
@@ -763,26 +786,19 @@ function float{T}(A::AbstractArray{T}) | |
convert(AbstractArray{typeof(float(zero(T)))}, A) | ||
end | ||
|
||
for fn in (:float,) | ||
@eval begin | ||
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r)) | ||
$fn(r::UnitRange) = $fn(r.start):$fn(last(r)) | ||
$fn(r::FloatRange) = FloatRange($fn(r.start), $fn(r.step), r.len, $fn(r.divisor)) | ||
function $fn(r::LinSpace) | ||
new_len = $fn(r.len) | ||
new_len == r.len || error(string(r, ": too long for ", $fn)) | ||
LinSpace($fn(r.start), $fn(r.stop), new_len, $fn(r.divisor)) | ||
end | ||
end | ||
float(r::StepRange) = float(r.start):float(r.step):float(last(r)) | ||
float(r::UnitRange) = float(r.start):float(last(r)) | ||
float(r::StepRangeLen) = StepRangeLen(float(r.ref), float(r.step), length(r), r.offset) | ||
function float(r::LinSpace) | ||
LinSpace(float(r.start), float(r.stop), length(r)) | ||
end | ||
|
||
# big, broadcast over arrays | ||
# TODO: do the definitions below primarily pertaining to integers belong in float.jl? | ||
function big end # no prior definitions of big in sysimg.jl, necessitating this | ||
broadcast(::typeof(big), r::UnitRange) = big(r.start):big(last(r)) | ||
broadcast(::typeof(big), r::StepRange) = big(r.start):big(r.step):big(last(r)) | ||
broadcast(::typeof(big), r::FloatRange) = FloatRange(big(r.start), big(r.step), r.len, big(r.divisor)) | ||
broadcast(::typeof(big), r::StepRangeLen) = StepRangeLen(big(r.ref), big(r.step), length(r), r.offset) | ||
function broadcast(::typeof(big), r::LinSpace) | ||
big(r.len) == r.len || throw(ArgumentError(string(r, ": too long for ", big))) | ||
LinSpace(big(r.start), big(r.stop), big(r.len), big(r.divisor)) | ||
LinSpace(big(r.start), big(r.stop), length(r)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess FloatRange didn't have a docstring? if you want the new one to go into the manual, it should be added to one of the stdlib doc index files