/usr/include/FLINT/fmpz.h is in libflint-dev 1.011-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | /*============================================================================
This file is part of FLINT.
FLINT is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
FLINT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FLINT; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===============================================================================*/
/****************************************************************************
fmpz.h: "flat" multi-precision integer format
Copyright (C) 2007, William Hart and David Harvey
*****************************************************************************/
#ifndef FLINT_FMPZ_H
#define FLINT_FMPZ_H
#ifdef __cplusplus
extern "C" {
#endif
#include <gmp.h>
#include "memory-manager.h"
#include "flint.h"
#include "long_extras.h"
typedef mp_limb_t * fmpz_t;
#define ABS(x) (((long) x < 0) ? -x : x)
#define NORM(coeff) \
do { \
if ((coeff)[0]) \
{ \
if ((long) (coeff)[0] < 0) \
{ \
while ((!(coeff)[-(coeff)[0]]) && (coeff)[0]) (coeff)[0]++; \
} else \
{ \
while ((!(coeff)[(coeff)[0]]) && (coeff)[0]) (coeff)[0]--; \
} \
} \
} while (0);
void fmpz_check_normalisation(const fmpz_t x);
static inline
fmpz_t fmpz_init(const unsigned long limbs)
{
return (fmpz_t) flint_heap_alloc(limbs + 1);
}
static inline
fmpz_t fmpz_realloc(fmpz_t f, const unsigned long limbs)
{
return (fmpz_t) flint_heap_realloc(f, limbs + 1);
}
static inline
void fmpz_clear(const fmpz_t f)
{
flint_heap_free(f);
}
void fmpz_print(fmpz_t in);
void fmpz_random_limbs2(fmpz_t x, unsigned long n);
static inline
unsigned long fmpz_size(const fmpz_t x)
{
long limb = (long) x[0];
return (unsigned long) ((limb < 0L) ? -limb : limb);
}
static inline
unsigned long fmpz_bits(const fmpz_t x)
{
unsigned long limbs = FLINT_ABS(x[0]);
unsigned long bits = FLINT_BIT_COUNT(x[limbs]);
if (limbs == 0) return 0;
return (((limbs-1)<<FLINT_LG_BITS_PER_LIMB) + bits);
}
// returns positive, negative or zero according to sign of x
static inline
long fmpz_sgn(const fmpz_t x)
{
return (long) x[0];
}
// res := x
// if x == 0, then res needs room only for the control limb
// if x != 0, res needs room for one limb beyond control limb
static inline
void fmpz_set_ui(fmpz_t res, const unsigned long x)
{
if (x)
{
res[0] = 1UL;
res[1] = x;
}
else
res[0] = 0UL;
}
// same as fmpz_set_ui
static inline
void fmpz_set_si(fmpz_t res, const long x)
{
if (x > 0L)
{
res[0] = 1L;
res[1] = x;
}
else if (x < 0L)
{
res[0] = -1L;
res[1] = -x;
}
else
res[0] = 0UL;
}
// returns nonzero if op1 == op2
static inline
int fmpz_equal(const fmpz_t op1, const fmpz_t op2)
{
// if the signs/sizes are different, they can't be equal
if (op1[0] != op2[0])
return 0;
// compare actual limbs
for (long i = 0; i < fmpz_size(op1); i++)
{
if (op1[i+1] != op2[i+1])
return 0;
}
return 1;
}
// sets res := op
// doesn't check for aliasing (i.e. if op == res, it will stupidly copy data)
// assumes res has enough room
static inline
void fmpz_set(fmpz_t res, const fmpz_t op)
{
long i = fmpz_size(op);
do
{
res[i] = op[i];
i--;
}
while (i >= 0);
}
// res must have enough space for x
void mpz_to_fmpz(fmpz_t res, const mpz_t x);
void fmpz_to_mpz(mpz_t res, const fmpz_t x);
void fmpz_add(fmpz_t coeffs_out, const fmpz_t in1, const fmpz_t in2);
void fmpz_add_ui_inplace(fmpz_t output, const unsigned long x);
void fmpz_add_ui(fmpz_t output, const fmpz_t input, const unsigned long x);
void __fmpz_add_ui_inplace(fmpz_t output, const unsigned long x);
void fmpz_sub(fmpz_t coeffs_out, const fmpz_t in1, const fmpz_t in2);
void fmpz_sub_ui_inplace(fmpz_t output, const unsigned long x);
void fmpz_sub_ui(fmpz_t output, const fmpz_t input, const unsigned long x);
void fmpz_mul(fmpz_t res, const fmpz_t a, const fmpz_t b);
void __fmpz_mul(fmpz_t res, const fmpz_t a, const fmpz_t b);
void fmpz_mul_ui(fmpz_t output, const fmpz_t input, const unsigned long x);
void fmpz_addmul(fmpz_t res, const fmpz_t a, const fmpz_t b);
void fmpz_tdiv(fmpz_t res, const fmpz_t a, const fmpz_t b);
void fmpz_fdiv(fmpz_t res, const fmpz_t a, const fmpz_t b);
void fmpz_tdiv_ui(fmpz_t output, const fmpz_t input, const unsigned long x);
unsigned long fmpz_mod_ui(const fmpz_t input, const unsigned long x);
void fmpz_pow_ui(fmpz_t output, const fmpz_t input, const unsigned long exp);
unsigned long __fmpz_power_of_two(const fmpz_t x);
void fmpz_div_2exp(fmpz_t output, fmpz_t x, unsigned long exp);
void fmpz_mul_2exp(fmpz_t output, fmpz_t x, unsigned long exp);
void fmpz_gcd(fmpz_t output, fmpz_t x1, fmpz_t x2);
/*
Computes the binomial coefficient next := bin(n, k) given prev = bin(n, k-1)
The output is assumed to have enough space for the result, plus one extra limb
(for efficiency reasons)
Note: bin(n, k) requires at most n bits to represent it when n and k are positive
Currently only implemented for positive n and k
Todo: implement this for negative n and k
*/
static inline
void __fmpz_binomial_next(fmpz_t next, const fmpz_t prev, const long n, const long k)
{
fmpz_mul_ui(next, prev, n-k+1);
fmpz_tdiv_ui(next, next, k);
}
static inline
int fmpz_is_one(const fmpz_t f)
{
if (f[0] == 1L) return (f[1] == 1L);
else return 0;
}
static inline
int fmpz_is_zero(const fmpz_t f)
{
return (f[0] == 0L);
}
static inline
void __fmpz_normalise(const fmpz_t f)
{
NORM(f);
}
static inline
int fmpz_cmpabs(const fmpz_t f1, const fmpz_t f2)
{
unsigned long size1 = FLINT_ABS(f1[0]);
unsigned long size2 = FLINT_ABS(f2[0]);
if (size1 < size2) return -1;
if (size1 > size2) return 1;
return mpn_cmp(f1 + 1, f2 + 1, size1);
}
void fmpz_sqrtrem(fmpz_t sqrt, fmpz_t rem, fmpz_t n);
/*
Computes the unique integer mod m1*m2 which is r1 mod m1 and r2 mod m2
where m1 is an fmpz_t and m2 is a coprime unsigned long.
Assumes both m1 and m2 are reduced modulo their respective moduli.
c must be set to m1^{-1} mod m2.
pre must be set to a precomputed inverse of m2
Assumes the number of bits of m2 is at most FLINT_D_BITS-1
*/
static inline
void fmpz_CRT_ui_precomp(fmpz_t out, fmpz_t r1, fmpz_t m1, unsigned long r2,
unsigned long m2, unsigned long c, double pre)
{
unsigned long r1mod = fmpz_mod_ui(r1, m2);
unsigned long s = z_submod(r2, r1mod, m2);
s = z_mulmod_precomp(s, c, m2, pre);
fmpz_t sm1 = fmpz_init(m1[0] + 1);
fmpz_mul_ui(sm1, m1, s);
fmpz_add(out, r1, sm1);
fmpz_clear(sm1);
}
/*
As for fmpz_CRT_ui_precomp except that it assumes the number of bits of m2
is at most FLINT_BITS-1
*/
static inline
void fmpz_CRT_ui2_precomp(fmpz_t out, fmpz_t r1, fmpz_t m1, unsigned long r2,
unsigned long m2, unsigned long c, double pre)
{
unsigned long r1mod = fmpz_mod_ui(r1, m2);
unsigned long s = z_submod(r2, r1mod, m2);
s = z_mulmod2_precomp(s, c, m2, pre);
fmpz_t sm1 = fmpz_init(m1[0] + 1);
fmpz_mul_ui(sm1, m1, s);
fmpz_add(out, r1, sm1);
fmpz_clear(sm1);
}
#ifdef __cplusplus
}
#endif
#endif
// *************** end of file
|