Skip to content

prevent negative usec values in oct-time.cc#49

Open
AADARSHPUROHIT466 wants to merge 7 commits intognu-octave:defaultfrom
AADARSHPUROHIT466:fix-oct-time-negative-usec
Open

prevent negative usec values in oct-time.cc#49
AADARSHPUROHIT466 wants to merge 7 commits intognu-octave:defaultfrom
AADARSHPUROHIT466:fix-oct-time-negative-usec

Conversation

@AADARSHPUROHIT466
Copy link
Contributor

This patch fixes incorrect microsecond decomposition for negative (pre-Unix-epoch) times in oct-time.cc.

Problem:

  • std::modf returns a negative fractional part for negative inputs.
  • This caused m_ot_usec to be negative, misrepresenting time values.

Solution:

  • Reimplemented constructor using floor-based decomposition.
  • (d - floor(d)) always yields a positive fraction in [0,1).
  • Ensures m_ot_usec is consistently in [0, 999999] range.

Impact:

  • Correct handling of pre-Unix-epoch dates.
  • Improves accuracy and consistency of time representation.

@sonarqubecloud
Copy link

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.

1 participant

Comments