Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

79 lines
2.7 KiB

  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef TAIA_H
  3. #define TAIA_H
  4. /* Times with 1 attosecond precision */
  5. #include "tai.h"
  6. #include "uint32.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /* A struct taia value is a number between 0 inclusive and 2^64
  11. * exclusive. The number is a multiple of 10^-18. The format of struct
  12. * taia is designed to speed up common operations; applications should
  13. * not look inside struct taia. */
  14. typedef struct taia {
  15. struct tai sec;
  16. uint32 nano; /* 0...999999999 */
  17. uint32 atto; /* 0...999999999 */
  18. } tai6464;
  19. /* extract seconds */
  20. void taia_tai(const tai6464 *source,tai64 *dest);
  21. /* get current time */
  22. void taia_now(struct taia *);
  23. /* return double-precision approximation; always nonnegative */
  24. double taia_approx(const tai6464 *);
  25. /* return double-precision approximation of the fraction part;
  26. * always nonnegative */
  27. double taia_frac(const tai6464 *);
  28. /* add source1 to source2 modulo 2^64 and put the result in dest.
  29. * The inputs and output may overlap */
  30. void taia_add(tai6464 *dest,const tai6464 *source1,const tai6464 *source2);
  31. /* add secs seconds to source modulo 2^64 and put the result in dest. */
  32. void taia_addsec(tai6464 *dest,const tai6464 *source,long secs);
  33. /* subtract source2 from source1 modulo 2^64 and put the result in dest.
  34. * The inputs and output may overlap */
  35. void taia_sub(tai6464 *,const tai6464 *,const tai6464 *);
  36. /* divide source by 2, rouding down to a multiple of 10^-18, and put the
  37. * result into dest. The input and output may overlap */
  38. void taia_half(tai6464 *dest,const tai6464 *source);
  39. /* return 1 if a is less than b, 0 otherwise */
  40. int taia_less(const tai6464 *a,const tai6464 *b);
  41. #define TAIA_PACK 16
  42. /* char buf[TAIA_PACK] can be used to store a TAI64NA label in external
  43. * representation, which can then be used to transmit the binary
  44. * representation over a network or store it on disk in a byte order
  45. * independent fashion */
  46. /* convert a TAI64NA label from internal format in src to external
  47. * TAI64NA format in buf. */
  48. void taia_pack(char *buf,const tai6464 *src);
  49. /* convert a TAI64NA label from external TAI64NA format in buf to
  50. * internal format in dest. */
  51. void taia_unpack(const char *buf,tai6464 *dest);
  52. #define TAIA_FMTFRAC 19
  53. /* print the 18-digit fraction part of t in decimal, without a decimal
  54. * point but with leading zeros, into the character buffer s, without a
  55. * terminating \0. It returns 18, the number of characters written. s
  56. * may be zero; then taia_fmtfrac returns 18 without printing anything.
  57. * */
  58. unsigned int taia_fmtfrac(char *s,const tai6464 *t);
  59. /* initialize t to secs seconds. */
  60. void taia_uint(tai6464 *t,unsigned int secs);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif