| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef LIBBF_H |
| 25 |
#define LIBBF_H |
| 26 |
|
| 27 |
#include <stddef.h> |
| 28 |
#include <stdint.h> |
| 29 |
|
| 30 |
#if defined(__SIZEOF_INT128__) && (INTPTR_MAX >= INT64_MAX) |
| 31 |
#define LIMB_LOG2_BITS 6 |
| 32 |
#else |
| 33 |
#define LIMB_LOG2_BITS 5 |
| 34 |
#endif |
| 35 |
|
| 36 |
#define LIMB_BITS (1 << LIMB_LOG2_BITS) |
| 37 |
|
| 38 |
#if LIMB_BITS == 64 |
| 39 |
typedef __int128 int128_t; |
| 40 |
typedef unsigned __int128 uint128_t; |
| 41 |
typedef int64_t slimb_t; |
| 42 |
typedef uint64_t limb_t; |
| 43 |
typedef uint128_t dlimb_t; |
| 44 |
#define BF_RAW_EXP_MIN INT64_MIN |
| 45 |
#define BF_RAW_EXP_MAX INT64_MAX |
| 46 |
|
| 47 |
#define LIMB_DIGITS 19 |
| 48 |
#define BF_DEC_BASE UINT64_C(10000000000000000000) |
| 49 |
|
| 50 |
#else |
| 51 |
|
| 52 |
typedef int32_t slimb_t; |
| 53 |
typedef uint32_t limb_t; |
| 54 |
typedef uint64_t dlimb_t; |
| 55 |
#define BF_RAW_EXP_MIN INT32_MIN |
| 56 |
#define BF_RAW_EXP_MAX INT32_MAX |
| 57 |
|
| 58 |
#define LIMB_DIGITS 9 |
| 59 |
#define BF_DEC_BASE 1000000000U |
| 60 |
|
| 61 |
#endif |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
#define BF_EXP_BITS_MIN 3 |
| 66 |
|
| 67 |
#define BF_EXP_BITS_MAX (LIMB_BITS - 3) |
| 68 |
|
| 69 |
#define BF_EXT_EXP_BITS_MAX (BF_EXP_BITS_MAX + 1) |
| 70 |
|
| 71 |
#define BF_PREC_MIN 2 |
| 72 |
|
| 73 |
#define BF_PREC_MAX (((limb_t)1 << (LIMB_BITS - 2)) - 2) |
| 74 |
|
| 75 |
#define BF_PREC_INF (BF_PREC_MAX + 1) |
| 76 |
|
| 77 |
#if LIMB_BITS == 64 |
| 78 |
#define BF_CHKSUM_MOD (UINT64_C(975620677) * UINT64_C(9795002197)) |
| 79 |
#else |
| 80 |
#define BF_CHKSUM_MOD 975620677U |
| 81 |
#endif |
| 82 |
|
| 83 |
#define BF_EXP_ZERO BF_RAW_EXP_MIN |
| 84 |
#define BF_EXP_INF (BF_RAW_EXP_MAX - 1) |
| 85 |
#define BF_EXP_NAN BF_RAW_EXP_MAX |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
typedef struct { |
| 92 |
struct bf_context_t *ctx; |
| 93 |
int sign; |
| 94 |
slimb_t expn; |
| 95 |
limb_t len; |
| 96 |
limb_t *tab; |
| 97 |
} bf_t; |
| 98 |
|
| 99 |
typedef struct { |
| 100 |
|
| 101 |
struct bf_context_t *ctx; |
| 102 |
int sign; |
| 103 |
slimb_t expn; |
| 104 |
limb_t len; |
| 105 |
limb_t *tab; |
| 106 |
} bfdec_t; |
| 107 |
|
| 108 |
typedef enum { |
| 109 |
BF_RNDN, |
| 110 |
BF_RNDZ, |
| 111 |
BF_RNDD, |
| 112 |
BF_RNDU, |
| 113 |
BF_RNDNA, |
| 114 |
BF_RNDA, |
| 115 |
BF_RNDF, |
| 116 |
|
| 117 |
} bf_rnd_t; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
#define BF_FLAG_SUBNORMAL (1 << 3) |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
#define BF_FLAG_RADPNT_PREC (1 << 4) |
| 126 |
|
| 127 |
#define BF_RND_MASK 0x7 |
| 128 |
#define BF_EXP_BITS_SHIFT 5 |
| 129 |
#define BF_EXP_BITS_MASK 0x3f |
| 130 |
|
| 131 |
|
| 132 |
#define BF_FLAG_EXT_EXP (BF_EXP_BITS_MASK << BF_EXP_BITS_SHIFT) |
| 133 |
|
| 134 |
|
| 135 |
typedef uint32_t bf_flags_t; |
| 136 |
|
| 137 |
typedef void *bf_realloc_func_t(void *opaque, void *ptr, size_t size); |
| 138 |
|
| 139 |
typedef struct { |
| 140 |
bf_t val; |
| 141 |
limb_t prec; |
| 142 |
} BFConstCache; |
| 143 |
|
| 144 |
typedef struct bf_context_t { |
| 145 |
void *realloc_opaque; |
| 146 |
bf_realloc_func_t *realloc_func; |
| 147 |
BFConstCache log2_cache; |
| 148 |
BFConstCache pi_cache; |
| 149 |
struct BFNTTState *ntt_state; |
| 150 |
} bf_context_t; |
| 151 |
|
| 152 |
static inline int bf_get_exp_bits(bf_flags_t flags) |
| 153 |
{ |
| 154 |
int e; |
| 155 |
e = (flags >> BF_EXP_BITS_SHIFT) & BF_EXP_BITS_MASK; |
| 156 |
if (e == BF_EXP_BITS_MASK) |
| 157 |
return BF_EXP_BITS_MAX + 1; |
| 158 |
else |
| 159 |
return BF_EXP_BITS_MAX - e; |
| 160 |
} |
| 161 |
|
| 162 |
static inline bf_flags_t bf_set_exp_bits(int n) |
| 163 |
{ |
| 164 |
return ((BF_EXP_BITS_MAX - n) & BF_EXP_BITS_MASK) << BF_EXP_BITS_SHIFT; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
#define BF_ST_INVALID_OP (1 << 0) |
| 169 |
#define BF_ST_DIVIDE_ZERO (1 << 1) |
| 170 |
#define BF_ST_OVERFLOW (1 << 2) |
| 171 |
#define BF_ST_UNDERFLOW (1 << 3) |
| 172 |
#define BF_ST_INEXACT (1 << 4) |
| 173 |
|
| 174 |
#define BF_ST_MEM_ERROR (1 << 5) |
| 175 |
|
| 176 |
#define BF_RADIX_MAX 36 |
| 177 |
|
| 178 |
static inline slimb_t bf_max(slimb_t a, slimb_t b) |
| 179 |
{ |
| 180 |
if (a > b) |
| 181 |
return a; |
| 182 |
else |
| 183 |
return b; |
| 184 |
} |
| 185 |
|
| 186 |
static inline slimb_t bf_min(slimb_t a, slimb_t b) |
| 187 |
{ |
| 188 |
if (a < b) |
| 189 |
return a; |
| 190 |
else |
| 191 |
return b; |
| 192 |
} |
| 193 |
|
| 194 |
void bf_context_init(bf_context_t *s, bf_realloc_func_t *realloc_func, |
| 195 |
void *realloc_opaque); |
| 196 |
void bf_context_end(bf_context_t *s); |
| 197 |
|
| 198 |
void bf_clear_cache(bf_context_t *s); |
| 199 |
|
| 200 |
static inline void *bf_realloc(bf_context_t *s, void *ptr, size_t size) |
| 201 |
{ |
| 202 |
return s->realloc_func(s->realloc_opaque, ptr, size); |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
static inline void *bf_malloc(bf_context_t *s, size_t size) |
| 207 |
{ |
| 208 |
return bf_realloc(s, NULL, size); |
| 209 |
} |
| 210 |
|
| 211 |
static inline void bf_free(bf_context_t *s, void *ptr) |
| 212 |
{ |
| 213 |
|
| 214 |
if (ptr) |
| 215 |
bf_realloc(s, ptr, 0); |
| 216 |
} |
| 217 |
|
| 218 |
void bf_init(bf_context_t *s, bf_t *r); |
| 219 |
|
| 220 |
static inline void bf_delete(bf_t *r) |
| 221 |
{ |
| 222 |
bf_context_t *s = r->ctx; |
| 223 |
|
| 224 |
if (s && r->tab) { |
| 225 |
bf_realloc(s, r->tab, 0); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
static inline void bf_neg(bf_t *r) |
| 230 |
{ |
| 231 |
r->sign ^= 1; |
| 232 |
} |
| 233 |
|
| 234 |
static inline int bf_is_finite(const bf_t *a) |
| 235 |
{ |
| 236 |
return (a->expn < BF_EXP_INF); |
| 237 |
} |
| 238 |
|
| 239 |
static inline int bf_is_nan(const bf_t *a) |
| 240 |
{ |
| 241 |
return (a->expn == BF_EXP_NAN); |
| 242 |
} |
| 243 |
|
| 244 |
static inline int bf_is_zero(const bf_t *a) |
| 245 |
{ |
| 246 |
return (a->expn == BF_EXP_ZERO); |
| 247 |
} |
| 248 |
|
| 249 |
static inline void bf_memcpy(bf_t *r, const bf_t *a) |
| 250 |
{ |
| 251 |
*r = *a; |
| 252 |
} |
| 253 |
|
| 254 |
int bf_set_ui(bf_t *r, uint64_t a); |
| 255 |
int bf_set_si(bf_t *r, int64_t a); |
| 256 |
void bf_set_nan(bf_t *r); |
| 257 |
void bf_set_zero(bf_t *r, int is_neg); |
| 258 |
void bf_set_inf(bf_t *r, int is_neg); |
| 259 |
int bf_set(bf_t *r, const bf_t *a); |
| 260 |
void bf_move(bf_t *r, bf_t *a); |
| 261 |
int bf_get_float64(const bf_t *a, double *pres, bf_rnd_t rnd_mode); |
| 262 |
int bf_set_float64(bf_t *a, double d); |
| 263 |
|
| 264 |
int bf_cmpu(const bf_t *a, const bf_t *b); |
| 265 |
int bf_cmp_full(const bf_t *a, const bf_t *b); |
| 266 |
int bf_cmp(const bf_t *a, const bf_t *b); |
| 267 |
static inline int bf_cmp_eq(const bf_t *a, const bf_t *b) |
| 268 |
{ |
| 269 |
return bf_cmp(a, b) == 0; |
| 270 |
} |
| 271 |
|
| 272 |
static inline int bf_cmp_le(const bf_t *a, const bf_t *b) |
| 273 |
{ |
| 274 |
return bf_cmp(a, b) <= 0; |
| 275 |
} |
| 276 |
|
| 277 |
static inline int bf_cmp_lt(const bf_t *a, const bf_t *b) |
| 278 |
{ |
| 279 |
return bf_cmp(a, b) < 0; |
| 280 |
} |
| 281 |
|
| 282 |
int bf_add(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); |
| 283 |
int bf_sub(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); |
| 284 |
int bf_add_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, bf_flags_t flags); |
| 285 |
int bf_mul(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); |
| 286 |
int bf_mul_ui(bf_t *r, const bf_t *a, uint64_t b1, limb_t prec, bf_flags_t flags); |
| 287 |
int bf_mul_si(bf_t *r, const bf_t *a, int64_t b1, limb_t prec, |
| 288 |
bf_flags_t flags); |
| 289 |
int bf_mul_2exp(bf_t *r, slimb_t e, limb_t prec, bf_flags_t flags); |
| 290 |
int bf_div(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, bf_flags_t flags); |
| 291 |
#define BF_DIVREM_EUCLIDIAN BF_RNDF |
| 292 |
int bf_divrem(bf_t *q, bf_t *r, const bf_t *a, const bf_t *b, |
| 293 |
limb_t prec, bf_flags_t flags, int rnd_mode); |
| 294 |
int bf_rem(bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, |
| 295 |
bf_flags_t flags, int rnd_mode); |
| 296 |
int bf_remquo(slimb_t *pq, bf_t *r, const bf_t *a, const bf_t *b, limb_t prec, |
| 297 |
bf_flags_t flags, int rnd_mode); |
| 298 |
|
| 299 |
int bf_rint(bf_t *r, int rnd_mode); |
| 300 |
int bf_round(bf_t *r, limb_t prec, bf_flags_t flags); |
| 301 |
int bf_sqrtrem(bf_t *r, bf_t *rem1, const bf_t *a); |
| 302 |
int bf_sqrt(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 303 |
slimb_t bf_get_exp_min(const bf_t *a); |
| 304 |
int bf_logic_or(bf_t *r, const bf_t *a, const bf_t *b); |
| 305 |
int bf_logic_xor(bf_t *r, const bf_t *a, const bf_t *b); |
| 306 |
int bf_logic_and(bf_t *r, const bf_t *a, const bf_t *b); |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
#define BF_ATOF_NO_HEX (1 << 16) |
| 311 |
|
| 312 |
#define BF_ATOF_BIN_OCT (1 << 17) |
| 313 |
|
| 314 |
#define BF_ATOF_NO_NAN_INF (1 << 18) |
| 315 |
|
| 316 |
#define BF_ATOF_EXPONENT (1 << 19) |
| 317 |
|
| 318 |
int bf_atof(bf_t *a, const char *str, const char **pnext, int radix, |
| 319 |
limb_t prec, bf_flags_t flags); |
| 320 |
|
| 321 |
|
| 322 |
int bf_atof2(bf_t *r, slimb_t *pexponent, |
| 323 |
const char *str, const char **pnext, int radix, |
| 324 |
limb_t prec, bf_flags_t flags); |
| 325 |
int bf_mul_pow_radix(bf_t *r, const bf_t *T, limb_t radix, |
| 326 |
slimb_t expn, limb_t prec, bf_flags_t flags); |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
#define BF_FTOA_FORMAT_MASK (3 << 16) |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
#define BF_FTOA_FORMAT_FIXED (0 << 16) |
| 341 |
|
| 342 |
|
| 343 |
#define BF_FTOA_FORMAT_FRAC (1 << 16) |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
#define BF_FTOA_FORMAT_FREE (2 << 16) |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
#define BF_FTOA_FORMAT_FREE_MIN (3 << 16) |
| 362 |
|
| 363 |
|
| 364 |
#define BF_FTOA_FORCE_EXP (1 << 20) |
| 365 |
|
| 366 |
|
| 367 |
#define BF_FTOA_ADD_PREFIX (1 << 21) |
| 368 |
|
| 369 |
|
| 370 |
#define BF_FTOA_JS_QUIRKS (1 << 22) |
| 371 |
|
| 372 |
char *bf_ftoa(size_t *plen, const bf_t *a, int radix, limb_t prec, |
| 373 |
bf_flags_t flags); |
| 374 |
|
| 375 |
|
| 376 |
#define BF_GET_INT_MOD (1 << 0) |
| 377 |
int bf_get_int32(int *pres, const bf_t *a, int flags); |
| 378 |
int bf_get_int64(int64_t *pres, const bf_t *a, int flags); |
| 379 |
int bf_get_uint64(uint64_t *pres, const bf_t *a); |
| 380 |
|
| 381 |
|
| 382 |
void mp_print_str(const char *str, const limb_t *tab, limb_t n); |
| 383 |
void bf_print_str(const char *str, const bf_t *a); |
| 384 |
int bf_resize(bf_t *r, limb_t len); |
| 385 |
int bf_get_fft_size(int *pdpl, int *pnb_mods, limb_t len); |
| 386 |
int bf_normalize_and_round(bf_t *r, limb_t prec1, bf_flags_t flags); |
| 387 |
int bf_can_round(const bf_t *a, slimb_t prec, bf_rnd_t rnd_mode, slimb_t k); |
| 388 |
slimb_t bf_mul_log2_radix(slimb_t a1, unsigned int radix, int is_inv, |
| 389 |
int is_ceil1); |
| 390 |
int mp_mul(bf_context_t *s, limb_t *result, |
| 391 |
const limb_t *op1, limb_t op1_size, |
| 392 |
const limb_t *op2, limb_t op2_size); |
| 393 |
limb_t mp_add(limb_t *res, const limb_t *op1, const limb_t *op2, |
| 394 |
limb_t n, limb_t carry); |
| 395 |
limb_t mp_add_ui(limb_t *tab, limb_t b, size_t n); |
| 396 |
int mp_sqrtrem(bf_context_t *s, limb_t *tabs, limb_t *taba, limb_t n); |
| 397 |
int mp_recip(bf_context_t *s, limb_t *tabr, const limb_t *taba, limb_t n); |
| 398 |
limb_t bf_isqrt(limb_t a); |
| 399 |
|
| 400 |
|
| 401 |
int bf_const_log2(bf_t *T, limb_t prec, bf_flags_t flags); |
| 402 |
int bf_const_pi(bf_t *T, limb_t prec, bf_flags_t flags); |
| 403 |
int bf_exp(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 404 |
int bf_log(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 405 |
#define BF_POW_JS_QUIRKS (1 << 16) |
| 406 |
int bf_pow(bf_t *r, const bf_t *x, const bf_t *y, limb_t prec, bf_flags_t flags); |
| 407 |
int bf_cos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 408 |
int bf_sin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 409 |
int bf_tan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 410 |
int bf_atan(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 411 |
int bf_atan2(bf_t *r, const bf_t *y, const bf_t *x, |
| 412 |
limb_t prec, bf_flags_t flags); |
| 413 |
int bf_asin(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 414 |
int bf_acos(bf_t *r, const bf_t *a, limb_t prec, bf_flags_t flags); |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
static inline void bfdec_init(bf_context_t *s, bfdec_t *r) |
| 419 |
{ |
| 420 |
bf_init(s, (bf_t *)r); |
| 421 |
} |
| 422 |
static inline void bfdec_delete(bfdec_t *r) |
| 423 |
{ |
| 424 |
bf_delete((bf_t *)r); |
| 425 |
} |
| 426 |
|
| 427 |
static inline void bfdec_neg(bfdec_t *r) |
| 428 |
{ |
| 429 |
r->sign ^= 1; |
| 430 |
} |
| 431 |
|
| 432 |
static inline int bfdec_is_finite(const bfdec_t *a) |
| 433 |
{ |
| 434 |
return (a->expn < BF_EXP_INF); |
| 435 |
} |
| 436 |
|
| 437 |
static inline int bfdec_is_nan(const bfdec_t *a) |
| 438 |
{ |
| 439 |
return (a->expn == BF_EXP_NAN); |
| 440 |
} |
| 441 |
|
| 442 |
static inline int bfdec_is_zero(const bfdec_t *a) |
| 443 |
{ |
| 444 |
return (a->expn == BF_EXP_ZERO); |
| 445 |
} |
| 446 |
|
| 447 |
static inline void bfdec_memcpy(bfdec_t *r, const bfdec_t *a) |
| 448 |
{ |
| 449 |
bf_memcpy((bf_t *)r, (const bf_t *)a); |
| 450 |
} |
| 451 |
|
| 452 |
int bfdec_set_ui(bfdec_t *r, uint64_t a); |
| 453 |
int bfdec_set_si(bfdec_t *r, int64_t a); |
| 454 |
|
| 455 |
static inline void bfdec_set_nan(bfdec_t *r) |
| 456 |
{ |
| 457 |
bf_set_nan((bf_t *)r); |
| 458 |
} |
| 459 |
static inline void bfdec_set_zero(bfdec_t *r, int is_neg) |
| 460 |
{ |
| 461 |
bf_set_zero((bf_t *)r, is_neg); |
| 462 |
} |
| 463 |
static inline void bfdec_set_inf(bfdec_t *r, int is_neg) |
| 464 |
{ |
| 465 |
bf_set_inf((bf_t *)r, is_neg); |
| 466 |
} |
| 467 |
static inline int bfdec_set(bfdec_t *r, const bfdec_t *a) |
| 468 |
{ |
| 469 |
return bf_set((bf_t *)r, (bf_t *)a); |
| 470 |
} |
| 471 |
static inline void bfdec_move(bfdec_t *r, bfdec_t *a) |
| 472 |
{ |
| 473 |
bf_move((bf_t *)r, (bf_t *)a); |
| 474 |
} |
| 475 |
static inline int bfdec_cmpu(const bfdec_t *a, const bfdec_t *b) |
| 476 |
{ |
| 477 |
return bf_cmpu((const bf_t *)a, (const bf_t *)b); |
| 478 |
} |
| 479 |
static inline int bfdec_cmp_full(const bfdec_t *a, const bfdec_t *b) |
| 480 |
{ |
| 481 |
return bf_cmp_full((const bf_t *)a, (const bf_t *)b); |
| 482 |
} |
| 483 |
static inline int bfdec_cmp(const bfdec_t *a, const bfdec_t *b) |
| 484 |
{ |
| 485 |
return bf_cmp((const bf_t *)a, (const bf_t *)b); |
| 486 |
} |
| 487 |
static inline int bfdec_cmp_eq(const bfdec_t *a, const bfdec_t *b) |
| 488 |
{ |
| 489 |
return bfdec_cmp(a, b) == 0; |
| 490 |
} |
| 491 |
static inline int bfdec_cmp_le(const bfdec_t *a, const bfdec_t *b) |
| 492 |
{ |
| 493 |
return bfdec_cmp(a, b) <= 0; |
| 494 |
} |
| 495 |
static inline int bfdec_cmp_lt(const bfdec_t *a, const bfdec_t *b) |
| 496 |
{ |
| 497 |
return bfdec_cmp(a, b) < 0; |
| 498 |
} |
| 499 |
|
| 500 |
int bfdec_add(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, |
| 501 |
bf_flags_t flags); |
| 502 |
int bfdec_sub(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, |
| 503 |
bf_flags_t flags); |
| 504 |
int bfdec_add_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec, |
| 505 |
bf_flags_t flags); |
| 506 |
int bfdec_mul(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, |
| 507 |
bf_flags_t flags); |
| 508 |
int bfdec_mul_si(bfdec_t *r, const bfdec_t *a, int64_t b1, limb_t prec, |
| 509 |
bf_flags_t flags); |
| 510 |
int bfdec_div(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, |
| 511 |
bf_flags_t flags); |
| 512 |
int bfdec_divrem(bfdec_t *q, bfdec_t *r, const bfdec_t *a, const bfdec_t *b, |
| 513 |
limb_t prec, bf_flags_t flags, int rnd_mode); |
| 514 |
int bfdec_rem(bfdec_t *r, const bfdec_t *a, const bfdec_t *b, limb_t prec, |
| 515 |
bf_flags_t flags, int rnd_mode); |
| 516 |
int bfdec_rint(bfdec_t *r, int rnd_mode); |
| 517 |
int bfdec_sqrt(bfdec_t *r, const bfdec_t *a, limb_t prec, bf_flags_t flags); |
| 518 |
int bfdec_round(bfdec_t *r, limb_t prec, bf_flags_t flags); |
| 519 |
int bfdec_get_int32(int *pres, const bfdec_t *a); |
| 520 |
int bfdec_pow_ui(bfdec_t *r, const bfdec_t *a, limb_t b); |
| 521 |
|
| 522 |
char *bfdec_ftoa(size_t *plen, const bfdec_t *a, limb_t prec, bf_flags_t flags); |
| 523 |
int bfdec_atof(bfdec_t *r, const char *str, const char **pnext, |
| 524 |
limb_t prec, bf_flags_t flags); |
| 525 |
|
| 526 |
|
| 527 |
extern const limb_t mp_pow_dec[LIMB_DIGITS + 1]; |
| 528 |
void bfdec_print_str(const char *str, const bfdec_t *a); |
| 529 |
static inline int bfdec_resize(bfdec_t *r, limb_t len) |
| 530 |
{ |
| 531 |
return bf_resize((bf_t *)r, len); |
| 532 |
} |
| 533 |
int bfdec_normalize_and_round(bfdec_t *r, limb_t prec1, bf_flags_t flags); |
| 534 |
|
| 535 |
#endif |