Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346/****************************************************************************1**2*W integer.h GAP source Martin Schönert3** & Alice Niemeyer4** & Werner Nickel5**6**7*Y Copyright (C) 1996, Lehrstuhl D für Mathematik, RWTH Aachen, Germany8*Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland9*Y Copyright (C) 2002 The GAP Group10**11** This file declares the functions handling arbitrary size integers.12*/1314#ifndef GAP_INTEGER_H15#define GAP_INTEGER_H1617#ifdef USE_GMP /* then use the gmp version of the header file */18#include "gmpints.h"19#else /* read the rest of this file */202122/****************************************************************************23**2425*T TypDigit . . . . . . . . . . . . . . . . . . . . type of a single digit26**27** 'TypDigit' is the type of a single digit of an arbitrary size integer.28** This is of course unsigned short int, which gives us the 16 bits we want.29*/30#ifdef SYS_IS_64_BIT31typedef UInt4 TypDigit;32#define INTEGER_UNIT_SIZE 433#define INTEGER_ALLOCATION_SIZE 1634#else35typedef UInt2 TypDigit;36#define INTEGER_UNIT_SIZE 237#define INTEGER_ALLOCATION_SIZE 838#endif3940#define NR_DIGIT_BITS (8 * sizeof(TypDigit))41#define INTBASE (1UL << NR_DIGIT_BITS)42#define NR_SMALL_INT_BITS (2*NR_DIGIT_BITS - 4)43#define SIZE_INT(op) (SIZE_OBJ(op) / sizeof(TypDigit))44#define ADDR_INT(op) ((TypDigit*)ADDR_OBJ(op))454647/**************************************************************************48** The following two functions convert a C Int or UInt respectively into49** a GAP integer, either an immediate, small integer if possible or50** otherwise a new GAP bag with TNUM T_INTPOS or T_INTNEG.51**52*F ObjInt_Int(Int i)53*F ObjInt_UInt(UInt i)54**55****************************************************************************/5657Obj ObjInt_Int(Int i);58Obj ObjInt_UInt(UInt i);596061/****************************************************************************62**63*F PrintInt( <int> ) . . . . . . . . . . . . . . . print an integer constant64**65** 'PrintInt' prints the integer <int> in the usual decimal notation.66** 'PrintInt' handles objects of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.67*/68extern void PrintInt (69Obj op );707172/****************************************************************************73**74*F EqInt( <intL>, <intR> ) . . . . . . . . . test if two integers are equal75**76** 'EqInt' returns 1 if the two integer arguments <intL> and <intR> are77** equal and 0 otherwise.78*/79extern Int EqInt (80Obj opL,81Obj opR );828384/****************************************************************************85**86*F LtInt( <intL>, <intR> ) . . . . . test if an integer is less than another87**88** 'LtInt' returns 1 if the integer <intL> is strictly less than the integer89** <intR> and 0 otherwise.90*/91extern Int LtInt (92Obj opL,93Obj opR );949596/****************************************************************************97**98*F SumInt( <intL>, <intR> ) . . . . . . . . . . . . . . sum of two integers99**100** 'SumInt' returns the sum of the two integer arguments <intL> and <intR>.101** 'SumInt' handles operands of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.102**103** It can also be used in the cases that both operands are small integers104** and the result is a small integer too, i.e., that no overflow occurs.105** This case is usually already handled in 'EvalSum' for a better efficiency.106*/107extern Obj SumInt (108Obj opL,109Obj opR );110111112/****************************************************************************113**114*F DiffInt( <intL>, <intR> ) . . . . . . . . . . difference of two integers115**116** 'DiffInt' returns the difference of the two integer arguments <intL> and117** <intR>. 'DiffInt' handles operands of type 'T_INT', 'T_INTPOS' and118** 'T_INTNEG'.119**120** It can also be used in the cases that both operands are small integers121** and the result is a small integer too, i.e., that no overflow occurs.122** This case is usually already handled in 'EvalDiff' for a better efficiency.123*/124extern Obj DiffInt (125Obj opL,126Obj opR );127128129/****************************************************************************130**131*F ProdInt( <intL>, <intR> ) . . . . . . . . . . . . product of two integers132**133** 'ProdInt' returns the product of the two integer arguments <intL> and134** <intR>. 'ProdInt' handles operands of type 'T_INT', 'T_INTPOS' and135** 'T_INTNEG'.136**137** It can also be used in the cases that both operands are small integers138** and the result is a small integer too, i.e., that no overflow occurs.139** This case is usually already handled in 'EvalProd' for a better efficiency.140*/141extern Obj ProdInt (142Obj opL,143Obj opR );144145146/****************************************************************************147**148*F ModInt( <intL>, <intR> ) . . representant of residue class of an integer149**150** 'ModInt' returns the smallest positive representant of the residue class151** of the integer <intL> modulo the integer <intR>. 'ModInt' handles152** operands of type 'T_INT', 'T_INTPOS', 'T_INTNEG'.153**154** It can also be used in the cases that both operands are small integers155** and the result is a small integer too, i.e., that no overflow occurs.156** This case is usually already handled in 'EvalMod' for a better efficiency.157*/158extern Obj ModInt (159Obj opL,160Obj opR );161162163/****************************************************************************164**165*F PowInt( <intL>, <intR> ) . . . . . . . . . . . . . . power of an integer166**167** 'PowInt' returns the <intR>-th (an integer) power of the integer <intL>.168** 'PowInt' is handles operands of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.169**170** It can also be used in the cases that both operands are small integers171** and the result is a small integer too, i.e., that no overflow occurs.172** This case is usually already handled in 'EvalPow' for a better efficiency.173*/174extern Obj PowInt (175Obj opL,176Obj opR );177178179/****************************************************************************180**181*F QuoInt( <intL>, <intR> ) . . . . . . . . . . . quotient of two integers182**183** 'QuoInt' returns the integer part of the two integers <intL> and <intR>.184** 'QuoInt' handles operands of type 'T_INT', 'T_INTPOS' and 'T_INTNEG'.185**186** It can also be used in the cases that both operands are small integers187** and the result is a small integer too, i.e., that no overflow occurs.188**189** Note that this routine is not called from 'EvalQuo', the division of two190** integers yields a rational and is therefor performed in 'QuoRat'.191** This operation is however available through the internal function 'Quo'.192*/193extern Obj QuoInt (194Obj opL,195Obj opR );196197198/****************************************************************************199**200*F RemInt( <intL>, <intR> ) . . . . . . . . . . . remainder of two integers201**202** 'RemInt' returns the remainder of the quotient of the integers <intL>203** and <intR>. 'RemInt' handles operands of type 'T_INT', 'T_INTPOS' and204** 'T_INTNEG'.205**206** Note that the remainder is different from the value returned by the 'mod'207** operator which is always positive.208*/209extern Obj RemInt (210Obj opL,211Obj opR );212213214/****************************************************************************215**216*F GcdInt( <opL>, <opR> ) . . . . . . . . . . . . . . . gcd of two integers217**218** 'GcdInt' returns the gcd of the two integers <opL> and <opR>.219*/220extern Obj GcdInt (221Obj opL,222Obj opR );223224225extern Int CLog2Int(Int a);226extern Obj FuncLog2Int( Obj self, Obj intnum);227228/****************************************************************************229**230231*F * * * * * * * * * * * * * initialize package * * * * * * * * * * * * * * *232*/233234/****************************************************************************235** \236\237238*F InitInfoInt() . . . . . . . . . . . . . . . . . . table of init functions239*/240StructInitInfo * InitInfoInt ( void );241242243#endif // USE_GMP244245#endif // GAP_INTEGER_H246247/****************************************************************************248**249*E integer.c . . . . . . . . . . . . . . . . . . . . . . . . . . . ends here250*/251252253