From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!aioe.org!0nYzhFpEeoH2MFWixtUlcg.user.gioia.aioe.org.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Ada.Real_Time.Time_First Date: Wed, 09 Dec 2020 12:30:44 +0000 Organization: Aioe.org NNTP Server Message-ID: NNTP-Posting-Host: 0nYzhFpEeoH2MFWixtUlcg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (darwin) Cancel-Lock: sha1:8d5lwFNtcPWyo7OJczvuNbyFayg= X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader02.eternal-september.org comp.lang.ada:60769 List-Id: I opened an issue[1] on Cortex GNAT RTS, saying You’d expect Ada.Real_Time.Time_First to be quite a long time before any possible value of Ada.Real_Time.Clock; but in fact the system starts with Clock equal to Time_First. On the other hand, I had written Last_Flight_Command_Time : Ada.Real_Time.Time := Ada.Real_Time.Time_First; ... Quad_Is_Flying := Ada.Real_Time.To_Duration (Now - Last_Flight_Command_Time) < In_Flight_Time_Threshold; but Now - Last_Flight_Command_Time is going to be quite small, to start with, so Quad_Is_Flying is going to be True when it shouldn't be. The workround I used was Quad_Is_Flying := Last_Flight_Command_Time /= Ada.Real_Time.Time_First and then Ada.Real_Time.To_Duration (Now - Last_Flight_Command_Time) < In_Flight_Time_Threshold; In other words, I was using Time_First as a flag to indicate that Last_Flight_Command_Time was invalid. What would your standard pattern for this sort of problem be? Esepecially considering that if I make Time_First a large negative number I'll get the opposite problem, e.g. predicting ahead for a very large interval, possibly even leading to numeric overflows. I'm thinking of a Time type with the concept of validity, possibly built round type Time (Valid : Boolean := False) is record case Valid is when True => Value : Ada.Real_Time.Time; when False => null; end case; end record; and addition, etc with appropriate preconditions. (not so sure about the discriminated record, might be more trouble than it's worth) [1] https://github.com/simonjwright/cortex-gnat-rts/issues/33