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

jd2cal #23

Merged
merged 10 commits into from
Jun 6, 2018
Merged

jd2cal #23

merged 10 commits into from
Jun 6, 2018

Conversation

prakharcode
Copy link
Contributor

@helgee the type conversion is proving to be a problem. I've tried with round still the date part gives an error. @giordano any solution to this?

Copy link
Member

@helgee helgee left a comment

Choose a reason for hiding this comment

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

The problem is not the rounding but the fact that C code uses integer division. Have a look 👍

f += 1.0
end
d = round(date-f1) + round(date1-f2) + round(f1+f2-f)
jd = round(d) + 1.
Copy link
Member

Choose a reason for hiding this comment

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

You have to be careful with your number types. jd for example is a long in the C code, i.e. an integer. Many of the lines below use integer arithmetic in the C version including integer (truncating) division whereas your version uses floating point math which will get different results.

jd = Int(round(d) + 1)

d = round(date-f1) + round(date1-f2) + round(f1+f2-f)
jd = round(d) + 1.

l = jd + 68569.
Copy link
Member

Choose a reason for hiding this comment

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

Every long literal in C, e.g. 68569L, should be an integer literal in Julia.

i = (4000. * (l + 1.)) / 1461001.
l -= (1461. * i) / 4. - 31.
k = (80. * l) / 2447.
id = Int(floor((l - (2447. * k) / 80.)))
Copy link
Member

Choose a reason for hiding this comment

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

This is casting from long to int in the C code which means you do not need it here since all parameters should already be ints.

jd = round(d) + 1.

l = jd + 68569.
n = (4. * l) / 146097.
Copy link
Member

Choose a reason for hiding this comment

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

You need to explicitly use integer division on the Julia side, e.g. n = (4 * l) ÷ 146097 (÷ tab-completes from \div in editors with Julia plugins) or n = div((4 * l), 146097). I would prefer the unicode operator.

@inline function jd2cal(jd1, jd2)
dj = jd1 + jd2
if dj < JD_MIN || dj > JD_MAX
error("Date is not acceptable")
Copy link
Member

Choose a reason for hiding this comment

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

You should use plain error only in scripts. Use more explicit exception types in library code. Here throw(ArgumentError("...")) would be appropriate.

I would also like a more descriptive error message, e.g. "Julian date is outside of the representable range." or something like that.

@codecov-io
Copy link

codecov-io commented Jun 5, 2018

Codecov Report

Merging #23 into master will decrease coverage by 11.17%.
The diff coverage is 61.11%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #23       +/-   ##
===========================================
- Coverage    97.6%   86.42%   -11.18%     
===========================================
  Files           6        7        +1     
  Lines         292      361       +69     
===========================================
+ Hits          285      312       +27     
- Misses          7       49       +42
Impacted Files Coverage Δ
src/AstroTime.jl 100% <ø> (ø) ⬆️
src/utils.jl 0% <0%> (ø)
src/conversions.jl 99.06% <97.05%> (-0.94%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 27cbb88...319b03e. Read the comment docs.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 173

  • 66 of 108 (61.11%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-11.2%) to 86.427%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/conversions.jl 66 68 97.06%
src/utils.jl 0 40 0.0%
Totals Coverage Status
Change from base Build 159: -11.2%
Covered Lines: 312
Relevant Lines: 361

💛 - Coveralls

@helgee helgee merged commit 0c3938b into JuliaAstro:master Jun 6, 2018
@prakharcode prakharcode deleted the jd2cal branch July 1, 2018 12:11
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.

5 participants