fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
tai.h
Go to the documentation of this file.
1#ifndef TAI_H
2#define TAI_H
3
4/*
5 * Revision 20160728, Kai Peter
6 * - switched to 'uint_t.h'
7*/
8/* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
9
10/* Times with 1 second precision */
11
12#include "uint_t.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/* A struct tai value is an integer between 0 inclusive and 2^64
19 * exclusive. The format of struct tai is designed to speed up common
20 * operations; applications should not look inside struct tai.
21 *
22 * A struct tai variable is commonly used to store a TAI64 label. Each
23 * TAI64 label refers to one second of real time. TAI64 labels span a
24 * range of hundreds of billions of years.
25 *
26 * A struct tai variable may also be used to store the numerical
27 * difference between two TAI64 labels.
28 * See http://cr.yp.to/libtai/tai64.html */
29
30typedef struct tai {
33
34
35#define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64) (u)))
36
37/* tai_now puts the current time into t. More precisely: tai_now puts
38 * into t its best guess as to the TAI64 label for the 1-second interval
39 * that contains the current time.
40 *
41 * This implementation of tai_now assumes that the time_t returned from
42 * the time function represents the number of TAI seconds since
43 * 1970-01-01 00:00:10 TAI. This matches the convention used by the
44 * Olson tz library in ``right'' mode. */
45void tai_now(struct tai *);
46
47/* tai_approx returns a double-precision approximation to t. The result
48 * of tai_approx is always nonnegative. */
49#define tai_approx(t) ((double) ((t)->x))
50
51/* tai_add adds a to b modulo 2^64 and puts the result into t. The
52 * inputs and output may overlap. */
53void tai_add(struct tai *,const struct tai *,const struct tai *);
54/* tai_sub subtracts b from a modulo 2^64 and puts the result into t.
55 * The inputs and output may overlap. */
56void tai_sub(struct tai *,const struct tai *,const struct tai *);
57/* tai_less returns 1 if a is less than b, 0 otherwise. */
58#define tai_less(t,u) ((t)->x < (u)->x)
59
60#define TAI_PACK 8
61/* tai_pack converts a TAI64 label from internal format in t to external
62 * TAI64 format in buf. */
63void tai_pack(char *,const struct tai *);
64/* tai_unpack converts a TAI64 label from external TAI64 format in buf
65 * to internal format in t. */
66void tai_unpack(const char *,struct tai *);
67
68void tai_uint(struct tai *,unsigned int);
69
70#ifdef __cplusplus
71}
72#endif
73
74#endif
void tai_now(struct tai *)
Definition: tai.c:16
void tai_add(struct tai *, const struct tai *, const struct tai *)
Definition: tai.c:11
void tai_unpack(const char *, struct tai *)
Definition: tai.c:46
void tai_sub(struct tai *, const struct tai *, const struct tai *)
Definition: tai.c:36
void tai_uint(struct tai *, unsigned int)
Definition: tai.c:41
void tai_pack(char *, const struct tai *)
Definition: tai.c:21
struct tai tai64
additional types and pack routines
unsigned long long uint64
Definition: uint_t.h:54
Definition: tai.h:30
uint64 x
Definition: tai.h:31