Hash :
df4d9d89
Author :
Baptiste
Date :
2024-03-01T14:36:29
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
/* c3
* Copyright 2022,2023 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#ifndef LIBC3_RATIO_H
#define LIBC3_RATIO_H
#include <stdarg.h>
#include <stdio.h>
#include "types.h"
/* Stack-allocation compatible functions, call ratio_clean after use. */
void ratio_clean (s_ratio *r);
s_ratio * ratio_init (s_ratio *dest);
s_ratio * ratio_init_integer (s_ratio *r, s_integer *numerator,
s_integer *denominator);
s_ratio * ratio_init_zero (s_ratio *r);
s_ratio * ratio_init_1 (s_ratio *r, const char *p);
s_ratio * ratio_init_copy (s_ratio *a, const s_ratio *x);
s_ratio * ratio_init_f32 (s_ratio *a, f32 x);
s_ratio * ratio_init_f64 (s_ratio *a, f64 x);
/* Constructors, call ratio_delete after use. */
s_ratio * ratio_new (void);
s_ratio * ratio_new_copy (const s_ratio *a);
/* Observers. */
s_str * ratio_inspect (const s_ratio *src, s_str *dest);
bool ratio_is_negative (const s_ratio *r);
bool ratio_is_zero (const s_ratio *r);
f32 ratio_to_f32 (const s_ratio *r);
f64 ratio_to_f64 (const s_ratio *r);
sw ratio_to_sw (const s_ratio *r);
s64 ratio_to_s64 (const s_ratio *r);
s32 ratio_to_s32 (const s_ratio *r);
s16 ratio_to_s16 (const s_ratio *r);
s8 ratio_to_s8 (const s_ratio *r);
uw ratio_to_uw (const s_ratio *r);
u64 ratio_to_u64 (const s_ratio *r);
u32 ratio_to_u32 (const s_ratio *r);
u16 ratio_to_u16 (const s_ratio *r);
u8 ratio_to_u8 (const s_ratio *r);
/* Operators. */
s_ratio * ratio_add (const s_ratio *a, const s_ratio *b,
s_ratio *dest);
s_ratio * ratio_div (const s_ratio *a, const s_ratio *b,
s_ratio *dest);
s_ratio * ratio_mul (const s_ratio *a, const s_ratio *b,
s_ratio *dest);
s_ratio * ratio_neg (const s_ratio *r, s_ratio *dest);
s_tag * ratio_sqrt (const s_ratio *r, s_tag *dest);
s_ratio * ratio_sub (const s_ratio *a, const s_ratio *b,
s_ratio *dest);
/* Setters. */
s_ratio * ratio_set_double (s_ratio *a, double x);
s_ratio * ratio_simplify(s_ratio *r, s_ratio *dest);
#endif /* LIBC3_RATIO_H */