Hash :
28a62667
Author :
Thomas de Grivel
Date :
2024-04-04T17:02:17
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
/* c3
* Copyright 2022-2024 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.
*/
/**' ,
* @file integer.h
* @brief Integer manipulation functions.
*
* Structure to manipulate byte strings.
*/
#ifndef LIBC3_INTEGER_H
#define LIBC3_INTEGER_H
#include "types.h"
#define MP_IS_ZERO(a) ((a)->used == 0)
/* Stack allocation compatible functions */
s_integer * integer_init (s_integer *i);
s_integer * integer_init_1 (s_integer *i, const char *p);
s_integer * integer_init_cast (s_integer *a, const s_sym *type,
const s_tag *tag);
s_integer * integer_init_copy (s_integer *a, const s_integer *src);
s_integer * integer_init_f32 (s_integer *a, f32 x);
s_integer * integer_init_f64 (s_integer *a, f64 x);
s_integer * integer_init_f128 (s_integer *a, f128 x);
s_integer * integer_init_ratio (s_integer *a, const s_ratio *r);
s_integer * integer_init_s8 (s_integer *a, s8 x);
s_integer * integer_init_s16 (s_integer *a, s16 x);
s_integer * integer_init_s32 (s_integer *a, s32 x);
s_integer * integer_init_s64 (s_integer *a, s64 x);
s_integer * integer_init_sw (s_integer *a, sw x);
s_integer * integer_init_u8 (s_integer *a, u8 x);
s_integer * integer_init_u16 (s_integer *a, u16 x);
s_integer * integer_init_u32 (s_integer *a, u32 x);
s_integer * integer_init_u64 (s_integer *a, u64 x);
s_integer * integer_init_uw (s_integer *a, uw x);
s_integer * integer_init_zero (s_integer *i);
void integer_clean (s_integer *i);
/* Setters */
s_integer * integer_set_f32 (s_integer *a, f32 x);
s_integer * integer_set_f64 (s_integer *a, f64 x);
s_integer * integer_set_f128 (s_integer *a, f128 x);
s_integer * integer_set_double (s_integer *a, double x);
s_integer * integer_set_ratio (s_integer *a, const s_ratio *r);
s_integer * integer_set_s32 (s_integer *a, s32 x);
s_integer * integer_set_s64 (s_integer *a, s64 x);
s_integer * integer_set_sw (s_integer *a, sw x);
s_integer * integer_set_u32 (s_integer *a, u32 x);
s_integer * integer_set_u64 (s_integer *a, u64 x);
s_integer * integer_set_uw (s_integer *a, uw x);
/* Operators. */
s_integer * integer_abs (const s_integer *a, s_integer *dest);
s_integer * integer_add (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_band (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_bnot (const s_integer *a, s_integer *dest);
s_integer * integer_bor (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_bxor (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_div (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_gcd (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_lcm (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_lshift (const s_integer *a, sw b, s_integer *dest);
s_integer * integer_mod (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_mul (const s_integer *a, const s_integer *b,
s_integer *dest);
s_integer * integer_neg (const s_integer *a, s_integer *dest);
s_integer * integer_pow (const s_integer *a, const s_integer *b,
s_integer *dest);
s_tag * integer_sqrt (const s_integer *a, s_tag *dest);
s_integer * integer_sqrt_positive (const s_integer *a, s_integer *dest);
s_integer * integer_sub (const s_integer *a, const s_integer *b,
s_integer *dest);
/* Constructors, call integer_delete after use. */
s_integer * integer_new (void);
s_integer * integer_new_copy (const s_integer *a);
/* Observers */
uw integer_bits (const s_integer *i);
uw integer_bytes (const s_integer *i);
bool integer_is_negative (const s_integer *i);
bool integer_is_positive (const s_integer *i);
bool integer_is_zero (const s_integer *i);
f32 integer_to_f32 (const s_integer *i);
f64 integer_to_f64 (const s_integer *i);
f128 integer_to_f128 (const s_integer *i);
s8 integer_to_s8 (const s_integer *i);
s16 integer_to_s16 (const s_integer *i);
s32 integer_to_s32 (const s_integer *i);
s64 integer_to_s64 (const s_integer *i);
sw integer_to_sw (const s_integer *i);
u8 integer_to_u8 (const s_integer *i);
u16 integer_to_u16 (const s_integer *i);
u32 integer_to_u32 (const s_integer *i);
u64 integer_to_u64 (const s_integer *i);
uw integer_to_uw (const s_integer *i);
#endif /* LIBC3_INTEGER_H */