comp.lang.ada
 help / color / mirror / Atom feed
* Ada.Real_Time.Time_First
@ 2020-12-09 12:30 Simon Wright
  2020-12-09 13:16 ` Ada.Real_Time.Time_First Dmitry A. Kazakov
  2020-12-09 14:21 ` Ada.Real_Time.Time_First Niklas Holsti
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Wright @ 2020-12-09 12:30 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-12-09 20:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 12:30 Ada.Real_Time.Time_First Simon Wright
2020-12-09 13:16 ` Ada.Real_Time.Time_First Dmitry A. Kazakov
2020-12-09 20:07   ` Ada.Real_Time.Time_First Simon Wright
2020-12-09 14:21 ` Ada.Real_Time.Time_First Niklas Holsti
2020-12-09 20:16   ` Ada.Real_Time.Time_First Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox