Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:15:26

0001 /*
0002     Copyright (C) 2010 Sebastian Pancratz
0003 
0004     This file is part of FLINT.
0005 
0006     FLINT is free software: you can redistribute it and/or modify it under
0007     the terms of the GNU Lesser General Public License (LGPL) as published
0008     by the Free Software Foundation; either version 3 of the License, or
0009     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
0010 */
0011 
0012 #ifndef LONG_EXTRAS_H
0013 #define LONG_EXTRAS_H
0014 
0015 #ifdef LONG_EXTRAS_INLINES_C
0016 #define LONG_EXTRAS_INLINE
0017 #else
0018 #define LONG_EXTRAS_INLINE static inline
0019 #endif
0020 
0021 #include "longlong.h"
0022 
0023 #ifdef __cplusplus
0024  extern "C" {
0025 #endif
0026 
0027 /* Properties ****************************************************************/
0028 
0029 size_t z_sizeinbase(slong n, int b);
0030 
0031 /* Checked arithmetic ********************************************************/
0032 
0033 LONG_EXTRAS_INLINE int z_mul_checked(slong * a, slong b, slong c)
0034 {
0035 #if defined(__GNUC__)
0036     return __builtin_mul_overflow(b, c, a);
0037 #else
0038     ulong ahi, alo;
0039     smul_ppmm(ahi, alo, b, c);
0040     *a = alo;
0041     return FLINT_SIGN_EXT(alo) != ahi;
0042 #endif
0043 }
0044 
0045 LONG_EXTRAS_INLINE int z_add_checked(slong * a, slong b, slong c)
0046 {
0047 #if defined(__GNUC__)
0048     return __builtin_add_overflow(b, c, a);
0049 #else
0050     int of = (b > 0 && c > WORD_MAX - b) || (b < 0 && c < WORD_MIN - b);
0051     *a = b + c;
0052     return of;
0053 #endif
0054 }
0055 
0056 LONG_EXTRAS_INLINE
0057 int z_mat22_det_is_negative(slong m11, slong m12, slong m21, slong m22)
0058 {
0059     ulong t1, t2, t3, t4;
0060     smul_ppmm(t1, t2, m11, m22);
0061     smul_ppmm(t3, t4, m12, m21);
0062     sub_ddmmss(t1, t2, t1, t2, t3, t4);
0063     return FLINT_SIGN_EXT(t1) != 0;
0064 }
0065 
0066 /* Randomisation  ************************************************************/
0067 
0068 slong z_randtest(flint_rand_t state);
0069 
0070 slong z_randtest_not_zero(flint_rand_t state);
0071 
0072 slong z_randint(flint_rand_t state, ulong limit);
0073 
0074 /*****************************************************************************/
0075 
0076 int z_kronecker(slong a, slong n);
0077 
0078 #ifdef __cplusplus
0079 }
0080 #endif
0081 
0082 #endif