Avatar ·

How to implement a function that triggers at a specific time?

📁 method

The task is to create a method that triggers at a specific hour.

I assume this should be done in an asynchronous method (so it doesn't interfere with the main program). I only have an idea of checking the system time periodically (in a loop) and, if the hour matches, executing some function, but isn't there another way? In case minutes are needed instead of hours.

Avatar ·

This is a common problem in almost any programming language. The fact is that the continuum of real values must be mapped in some way onto a finite set of machine values. This is usually done using a method described by the standard.

A 64-bit (double precision) bit layout will be as follows:

Accordingly, there are fundamentally numbers that cannot be represented exactly - in this case, 1/3 cannot be represented exactly. A discrepancy will arise in the region of 1e-8, which gives 29.99999999

You can look at the precision of the representation.

Log in to leave an answer

Blogs