From 88e12f4a22111903fc23488898f073502639635c Mon Sep 17 00:00:00 2001 From: Emil Williams Date: Fri, 20 Feb 2026 06:18:48 +0000 Subject: Make experimental and librarize --- chad/experimental/timespec.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 chad/experimental/timespec.h (limited to 'chad/experimental/timespec.h') diff --git a/chad/experimental/timespec.h b/chad/experimental/timespec.h new file mode 100644 index 0000000..f72f431 --- /dev/null +++ b/chad/experimental/timespec.h @@ -0,0 +1,40 @@ +#ifndef TIMESPEC_H +#define TIMESPEC_H +/* ripped partly from glibc */ +#include +#include +#include + +/* -- pontentially over designed and undertested. */ +/* -- consider this "LIKELY TO BE REVISED OR REMOVED!" */ +/* -- ESPECIALLY the generics and the from group */ + +long TIMESPEC_HZ = 1000000000L; + +typedef struct timespec timespec_t; + +static const timespec_t one_second = {1, 0}, zero_seconds = {0, 0}; + +f64 timespec_to_f64(timespec_t ts); +f32 timespec_to_f32(timespec_t ts); +double timespec_to_double(timespec_t ts); +float timespec_to_float(timespec_t ts); + +#ifdef TERRY_SMALL_FLOAT_IMPRECISE +#define from_timespec(ts,to) _Generic((to), double *: double_from_timespec, float *: float_from_timespec)(ts,to) +#else +#define from_timespec(ts,to) _Generic((to), f64 *: f64_from_timespec, f32 *: f32_from_timespec, double *: double_from_timespec, float *: float_from_timespec)(ts,to) +#endif + +void f64_from_timespec(timespec_t ts, f64 * r); +void f32_from_timespec(timespec_t ts, f32 * r); +void double_from_timespec(timespec_t ts, double * r); +void float_from_timespec(timespec_t ts, float * r); + +timespec_t timespec_add(timespec_t a, timespec_t b); +timespec_t timespec_sub(timespec_t a, timespec_t b); +/* -1, 0, 1 */ +int timespec_cmp(timespec_t a, timespec_t b); +timespec_t timespec_max(timespec_t a, timespec_t b); +timespec_t timespec_min(timespec_t a, timespec_t b); +#endif /* TIMESPEC_H */ -- cgit v1.2.3