File: taia.h

package info (click to toggle)
libowfat 0.30-2
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 4,180 kB
  • ctags: 1,478
  • sloc: ansic: 15,320; makefile: 22
file content (78 lines) | stat: -rw-r--r-- 2,743 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
#ifndef TAIA_H
#define TAIA_H

/* Times with 1 attosecond precision */

#include "tai.h"
#include "uint32.h"

#ifdef __cplusplus
extern "C" {
#endif

/* A struct taia value is a number between 0 inclusive and 2^64
 * exclusive. The number is a multiple of 10^-18. The format of struct
 * taia is designed to speed up common operations; applications should
 * not look inside struct taia. */
typedef struct taia {
  struct tai sec;
  uint32 nano; /* 0...999999999 */
  uint32 atto; /* 0...999999999 */
} tai6464;

/* extract seconds */
void taia_tai(const tai6464 *source,tai64 *dest);

/* get current time */
void taia_now(struct taia *);

/* return double-precision approximation; always nonnegative */
double taia_approx(const tai6464 *);
/* return double-precision approximation of the fraction part;
 * always nonnegative */
double taia_frac(const tai6464 *);

/* add source1 to source2 modulo 2^64 and put the result in dest.
 * The inputs and output may overlap */
void taia_add(tai6464 *dest,const tai6464 *source1,const tai6464 *source2);
/* add secs seconds to source modulo 2^64 and put the result in dest. */
void taia_addsec(tai6464 *dest,const tai6464 *source,long secs);
/* subtract source2 from source1 modulo 2^64 and put the result in dest.
 * The inputs and output may overlap */
void taia_sub(tai6464 *,const tai6464 *,const tai6464 *);
/* divide source by 2, rouding down to a multiple of 10^-18, and put the
 * result into dest.  The input and output may overlap */
void taia_half(tai6464 *dest,const tai6464 *source);
/* return 1 if a is less than b, 0 otherwise */
int taia_less(const tai6464 *a,const tai6464 *b);

#define TAIA_PACK 16
/* char buf[TAIA_PACK] can be used to store a TAI64NA label in external
 * representation, which can then be used to transmit the binary
 * representation over a network or store it on disk in a byte order
 * independent fashion */

/* convert a TAI64NA label from internal format in src to external
 * TAI64NA format in buf. */
void taia_pack(char *buf,const tai6464 *src);
/* convert a TAI64NA label from external TAI64NA format in buf to
 * internal format in dest. */
void taia_unpack(const char *buf,tai6464 *dest);

#define TAIA_FMTFRAC 19
/* print the 18-digit fraction part of t in decimal, without a decimal
 * point but with leading zeros, into the character buffer s, without a
 * terminating \0. It returns 18, the number of characters written. s
 * may be zero; then taia_fmtfrac returns 18 without printing anything.
 * */
unsigned int taia_fmtfrac(char *s,const tai6464 *t);

/* initialize t to secs seconds. */
void taia_uint(tai6464 *t,unsigned int secs);

#ifdef __cplusplus
}
#endif

#endif