-
Notifications
You must be signed in to change notification settings - Fork 10
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
Redesign of AstroPeriod
née Period
and other small refactorings
#63
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bf8bcf4
Set default format for all Epoch subtypes
helgee 2433d5d
Improve precision of Epoch subtraction
helgee eb39859
Track floating point error
helgee 16fd26f
Add AccurateArithmetic submodule
helgee 9a5dc1a
Refactor offset calculations
helgee d53ab59
Redesign periods to increase precision
helgee 4e0960f
Update CI
helgee cf067db
Bump minimum Julia version to 1.3
helgee e662781
Coverage
helgee d88b53a
Cleanup
helgee 3bb0ac3
Fix ambiguities with `Dates`
helgee b81ebb8
Document and harmonize UTC API
helgee 1c66906
Update documentation
helgee 7638187
Use old kw-arg syntax
helgee ddc21e7
Try again
helgee 4fdb65a
Update compat and bump version
helgee 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module AccurateArithmetic | ||
|
||
# Adapted from AccurateArithmetic.jl | ||
|
||
export two_sum, apply_offset | ||
|
||
@inline function two_sum(a, b) | ||
hi = a + b | ||
a1 = hi - b | ||
b1 = hi - a1 | ||
lo = (a - a1) + (b - b1) | ||
return hi, lo | ||
end | ||
|
||
@inline function two_hilo_sum(a, b) | ||
hi = a + b | ||
lo = b - (hi - a) | ||
return hi, lo | ||
end | ||
|
||
function four_sum(a, b, c, d) | ||
t0, t1 = two_sum(a, b) | ||
t2, t3 = two_sum(c, d) | ||
hi, t4 = two_sum(t0, t2) | ||
t5, lo = two_sum(t1, t3) | ||
hm, ml = two_sum(t4, t5) | ||
ml, lo = two_hilo_sum(ml, lo) | ||
hm, ml = two_hilo_sum(hm, ml) | ||
hi, hm = two_hilo_sum(hi,hm) | ||
return hi, hm, ml, lo | ||
end | ||
|
||
function handle_infinity(fraction) | ||
second = ifelse(fraction < 0, typemin(Int64), typemax(Int64)) | ||
return second, fraction, zero(fraction) | ||
end | ||
|
||
function apply_offset(s1::Int64, f1, e1, s2::Int64, f2, e2) | ||
isfinite(f1 + f2) || return handle_infinity(f1 + f2) | ||
|
||
sum, residual, _ = four_sum(f1, f2, e1, e2) | ||
int_seconds = floor(Int64, sum) | ||
second = s1 + s2 + int_seconds | ||
fraction = sum - int_seconds | ||
return second, fraction, residual | ||
end | ||
|
||
function apply_offset(s1::Int64, f1, e1, offset) | ||
isfinite(f1 + offset) || return handle_infinity(f1 + offset) | ||
|
||
s2 = floor(Int64, offset) | ||
f2 = offset - s2 | ||
return apply_offset(s1, f1, e1, s2, f2, 0.0) | ||
end | ||
|
||
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
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 |
---|---|---|
@@ -1,38 +1,18 @@ | ||
@inline function two_sum(a, b) | ||
hi = a + b | ||
a1 = hi - b | ||
b1 = hi - a1 | ||
lo = (a - a1) + (b - b1) | ||
return hi, lo | ||
end | ||
|
||
struct Epoch{S<:TimeScale, T} <: Dates.AbstractDateTime | ||
scale::S | ||
second::Int64 | ||
fraction::T | ||
function Epoch{S}(second::Int64, fraction::T) where {S<:TimeScale, T} | ||
return new{S, T}(S(), second, fraction) | ||
error::T | ||
function Epoch{S}(second::Int64, fraction::T, error::T=zero(T)) where {S<:TimeScale, T<:AbstractFloat} | ||
return new{S, T}(S(), second, fraction, error) | ||
end | ||
end | ||
|
||
Epoch{S,T}(ep::Epoch{S,T}) where {S,T} = ep | ||
|
||
@inline function apply_offset(second::Int64, fraction, offset) | ||
sum, residual = two_sum(fraction, offset) | ||
if !isfinite(sum) | ||
fraction′ = sum | ||
second′ = ifelse(sum < 0, typemin(Int64), typemax(Int64)) | ||
else | ||
int_secs = floor(Int64, sum) | ||
second′ = second + int_secs | ||
fraction′ = sum - int_secs + residual | ||
end | ||
return second′, fraction′ | ||
end | ||
|
||
function Epoch{S}(ep::Epoch{S}, Δt) where {S<:TimeScale} | ||
second, fraction = apply_offset(ep.second, ep.fraction, Δt) | ||
return Epoch{S}(second, fraction) | ||
second, fraction, error = apply_offset(ep.second, ep.fraction, ep.error, Δt) | ||
return Epoch{S}(second, fraction, error) | ||
end | ||
|
||
Base.show(io::IO, ep::Epoch) = print(io, DateTime(ep), " ", timescale(ep)) |
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 don't know if that's relevant, but
isfinite
is false also forNaN
.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.
Interesting question 🤔
Here is Orekit's answer about what to do with
NaN
which is kind of unsatisfactory 🤣: