<?xml version="1.0" encoding="UTF-8"?>
<!-- **************************************************************************
.... For copyright and licensing terms, see the file named COPYING.
.... **************************************************************************
.-->
<?xml-stylesheet href="docbook-xml.css" type="text/css"?>

<refentry id="taia">

<refmeta xmlns:xi="http://www.w3.org/2001/XInclude">
<refentrytitle>taia</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo class="manual">user commands</refmiscinfo>
<refmiscinfo class="source">djbwares</refmiscinfo>
<xi:include href="version.xml" />
</refmeta>

<refnamediv>
<refname>taia</refname>
<refpurpose>manipulate times with 1-attosecond precision</refpurpose>
</refnamediv>
<refsynopsisdiv>
<programlisting>
#include &lt;taia.h&gt;

double \fBtaia_approx\fP(&amp;\fIt\fR);

double \fBtaia_frac\fP(&amp;\fIt\fR);

void \fBtaia_tai\fP(&amp;\fIt\fR,&amp;\fIsec\fR);

int \fBtaia_less\fP(&amp;\fIa\fR,&amp;\fIb\fR);

void \fBtaia_add\fP(&amp;\fIt\fR,&amp;\fIa\fR,&amp;\fIb\fR);

void \fBtaia_sub\fP(&amp;\fIt\fR,&amp;\fIa\fR,&amp;\fIb\fR);

void \fBtaia_half\fP(&amp;\fIt\fR,&amp;\fIa\fR);

unsigned int \fBtaia_fmtfrac\fP(\fIs\fR,&amp;\fIt\fR);

struct taia \fIt\fR;

struct taia \fIa\fR;

struct taia \fIb\fR;

struct tai \fIsec\fR;

char *\fIs\fR;
</programlisting>
</refsynopsisdiv>
<refsection><title>Description</title>
A
<command>struct</command> taia
stores an integer between 0 inclusive and 2^64x10^18 exclusive.
The format of
<command>struct</command> taia
is designed to speed up common operations;
applications should not look inside
<command>struct</command> taia\fR.

A
<command>struct</command> taia
variable is commonly used to store
a TAI64NA label.
Each TAI64NA label refers to one attosecond of real time;
see
<command>http://pobox.com/~djb/proto/tai64.txt</command>
for more information.
The integer in the
<command>struct</command> taia
is 10^18 times the second count,
plus 10^9 times the nanosecond count,
plus the attosecond count.

A
<command>struct</command> taia
variable may also be used to store
the numerical difference between two TAI64NA labels.
</refsection>
<refsection><title>Arithmetic</title>
<command>taia_approx</command>
returns a double-precision approximation to
<replaceable>t</replaceable>/10^18.
The result of
<command>taia_approx</command>
is always nonnegative.

<command>taia_tai</command>
places into
<replaceable>sec</replaceable>
the integer part of
<replaceable>t</replaceable>/10^18.

<command>taia_frac</command>
returns a double-precision approximation to
the fraction part of
<replaceable>t</replaceable>/10^18.
The result of
<command>taia_frac</command>
is always nonnegative.

<command>taia_less</command>
returns 1 if
<replaceable>a</replaceable>
is smaller than
<replaceable>b</replaceable>,
0 otherwise.

<command>taia_add</command>
adds
<replaceable>a</replaceable>
and
<replaceable>b</replaceable>
modulo 2^64x10^18
and puts the result into
<replaceable>t</replaceable>.
The inputs and outputs may overlap.

<command>taia_sub</command>
subtracts
<replaceable>b</replaceable>
from
<replaceable>a</replaceable>
modulo 2^64x10^18
and puts the result into
<replaceable>t</replaceable>.
The inputs and outputs may overlap.

<command>taia_half</command>
divides
<replaceable>a</replaceable>
by 2, rounding down,
and puts the result into
<replaceable>t</replaceable>.
The input and output may overlap.
</refsection>
<refsection><title>Formatting</title>
<command>taia_fmtfrac</command>
prints the remainder of
<replaceable>t</replaceable>/10^18,
padded to exactly 18 digits,
into the character buffer
<replaceable>s</replaceable>,
without a terminating NUL.
It returns 18, the number of characters written.
<replaceable>s</replaceable>
may be zero;
then
<command>taia_fmtfrac</command>
returns 18 without printing anything.

The macro
<command>TAIA_FMTFRAC</command>
is defined as 19;
this is enough space for the output of
<command>taia_fmtfrac</command>
and a terminating NUL.
</refsection>

<refsection><title>See also</title>
<varlistentry><term><citerefentry><refentrytitle>taia_now</refentrytitle><manvolnum>3</manvolnum></citerefentry></term></varlistentry>
<varlistentry><term><citerefentry><refentrytitle>taia_pack</refentrytitle><manvolnum>3</manvolnum></citerefentry></term></varlistentry>
<varlistentry><term><citerefentry><refentrytitle>tai</refentrytitle><manvolnum>3</manvolnum></citerefentry></term></varlistentry>
</refsection>

<refsection>
<title>Author</title>
<para>
Original code and documentation by <personname><firstname>Daniel</firstname> <othername>J.</othername> <surname>Bernstein</surname></personname>.
Converted to DocBook XML by <personname><firstname>Jonathan</firstname> <surname>de Boyne Pollard</surname></personname>.
</para>
</refsection>
</refentry>
