GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/*Written by Paul Smith*/12#include "src/compiled.h" /* the GAP headers */3#include <stdlib.h> /* for abs */456/***************** The new GAP kernel functions ***************/78/**9GAP kernel C function to calculate ane return the absolute value of an integer.10This is assumed to be a GAP small integer (i.e. less than 2^28-1 or 2^60-111depending on whether the machine is 32- or 64-bit).12@param self The standard GAP first parameter13@param n The standard GAP first parameter14@return The maximum small integer (according to this kernel module).15**/16Obj FuncABSINT_HAP(Obj self, Obj n)17{18Int Cn;19Cn = INT_INTOBJ(n); /* Convert the GAP object n into a C integer */20Cn = abs(Cn); /* Get the absolute value of this integer */21return INTOBJ_INT(Cn); /* Convert it back to a GAP object and return it */22}232425/******************** The interface to GAP ***************/2627/**28Details of the functions to make available to GAP.29This is used in InitKernel() and InitLibrary()30*/31static StructGVarFunc GVarFuncs[] =32{33{"AbsInt_HAP", /* The function name in GAP */341, /* The number of parameters */35"n", /* The names of the parameters */36FuncABSINT_HAP, /* The C function to call */37"absint.c:FuncABSINT_HAP" /* A user-friendly description of where38this function is */39},4041{ 0 } /* Finish with an empty entry */42};43444546/**47The first function to be called when the library is loaded by the kernel.48**/49static Int InitKernel(StructInitInfo* module)50{51/* init filters and functions */52InitHdlrFuncsFromTable( GVarFuncs );5354/* return success */55return 0;56}575859/**60The second function to be called when the library is loaded by the kernel.61**/62static Int InitLibrary(StructInitInfo* module)63{64/* init filters and functions */65InitGVarFuncsFromTable( GVarFuncs );6667/* return success */68return 0;69}707172/**73Information about this library, returned when the library is loaded,74for example by Init__Dynamic(). This contains details of the library name,75and the further initialisation functions to call.76**/77static StructInitInfo module = {78#ifdef STATICMODULE79/* type = */ MODULE_STATIC,80#else81/* type = */ MODULE_DYNAMIC,82#endif83/* name = */ "absolute value of an integer",84/* revision_c = */ 0,85/* revision_h = */ 0,86/* version = */ 0,87/* crc = */ 0,88/* initKernel = */ InitKernel,89/* initLibrary = */ InitLibrary,90/* checkInit = */ 0,91/* preSave = */ 0,92/* postSave = */ 0,93/* postRestore = */ 094};959697#ifndef STATICGAP98/**99Function called by GAP as soon as the library is dynamically loaded.100This returns the StructInitInfo data for this library101**/102StructInitInfo * Init__Dynamic (void)103{104return &module;105}106#endif107StructInitInfo * Init__linbox(void)108{109return &module;110}111112113114