Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
xanthospap committed Dec 9, 2024
1 parent 2330250 commit 9b7b34a
Show file tree
Hide file tree
Showing 6 changed files with 2,937 additions and 6 deletions.
3 changes: 3 additions & 0 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ $> echo "2008:32" | build/ydoy2mjd | build/mjd2ymd
## ToDo:

* [] Add documentation
* [] Verify that tests (especially unit tests) run as supposed do in the Release
build. It seems for example, that `from_mjdepoch` does not run as suppposed to
(even erronuous asserts that should fail, don't!).

## For Developers

Expand Down
4 changes: 2 additions & 2 deletions include/tpdate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,10 @@ template <gconcepts::is_sec_dt T>
template <typename T, typename = std::enable_if_t<T::is_of_sec_type>>
#endif
inline datetime<T> from_mjdepoch(const TwoPartDate &t) noexcept {
dso::picoseconds nsec(static_cast<picoseconds::underlying_type>(
dso::picoseconds psec(static_cast<picoseconds::underlying_type>(
t.seconds().seconds() * picoseconds::sec_factor<double>()));
return datetime<T>(modified_julian_day(t.imjd()),
cast_to<picoseconds, T>(nsec));
cast_to<picoseconds, T>(psec));
}

} /* namespace dso */
Expand Down
2 changes: 1 addition & 1 deletion include/tpdate2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TwoPartDate2 {
: _mjd(b), _fday(s.seconds() / SEC_PER_DAY) {
this->normalize();
}

explicit TwoPartDate2(int b = 0,
FractionalDays d = FractionalDays{0}) noexcept
: _mjd(b), _fday(d.days()) {
Expand Down
20 changes: 17 additions & 3 deletions src/core/fundamental_types_generic_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,23 @@ constexpr Strg cast_to(Ssrc s) noexcept {
* this is: (1/1000)*2000 which is 0 because 1/1000 is 0, but
* (2000*1)/1000 = 2 which is correct.
*/
const auto numerator =
s.__member_ref__() * Strg::template sec_factor<long>();
return Strg(numerator / Ssrc::template sec_factor<long>());

/* there is a high chance that this may cause overflow; if we are dealing
* with anything higher than microseconds, resort to floating point
* compuation.
*/
// const auto numerator =
// s.__member_ref__() * Strg::template sec_factor<long>();
if constexpr (Ssrc::template sec_factor<long>() > 1'000'000) {
const auto scale = Strg::template sec_factor<double>() /
Ssrc::template sec_factor<double>();
const auto fsec = scale * s.__member_ref__();
return Strg(static_cast<typename Strg::underlying_type>(fsec));
} else {
const auto numerator =
s.__member_ref__() * Strg::template sec_factor<long>();
return Strg(numerator / Ssrc::template sec_factor<long>());
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,7 @@ add_internal_includes(leap_insertion_dates_mjd)
target_link_libraries(leap_insertion_dates_mjd PRIVATE datetime)
add_test(NAME leap_insertion_dates_mjd COMMAND leap_insertion_dates_mjd)

add_executable(from_mjdepoch from_mjdepoch.cpp)
add_internal_includes(from_mjdepoch)
target_link_libraries(from_mjdepoch PRIVATE datetime)
add_test(NAME from_mjdepoch COMMAND from_mjdepoch)
Loading

0 comments on commit 9b7b34a

Please sign in to comment.