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
|
/*Written by Paul Smith*/
#include "src/compiled.h" /* the GAP headers */
#include <stdlib.h> /* for abs */
/***************** The new GAP kernel functions ***************/
/**
GAP kernel C function to calculate ane return the absolute value of an integer.
This is assumed to be a GAP small integer (i.e. less than 2^28-1 or 2^60-1
depending on whether the machine is 32- or 64-bit).
@param self The standard GAP first parameter
@param n The standard GAP first parameter
@return The maximum small integer (according to this kernel module).
**/
Obj FuncABSINT_HAP(Obj self, Obj n)
{
Int Cn;
Cn = INT_INTOBJ(n); /* Convert the GAP object n into a C integer */
Cn = abs(Cn); /* Get the absolute value of this integer */
return INTOBJ_INT(Cn); /* Convert it back to a GAP object and return it */
}
/******************** The interface to GAP ***************/
/**
Details of the functions to make available to GAP.
This is used in InitKernel() and InitLibrary()
*/
static StructGVarFunc GVarFuncs[] =
{
{"AbsIntt_HAP", /* The function name in GAP */
1, /* The number of parameters */
"n", /* The names of the parameters */
FuncABSINT_HAP, /* The C function to call */
"absint.c:FuncABSINT_HAP" /* A user-friendly description of where
this function is */
},
{ 0 } /* Finish with an empty entry */
};
/**
The first function to be called when the library is loaded by the kernel.
**/
static Int InitKernel(StructInitInfo* module)
{
/* init filters and functions */
InitHdlrFuncsFromTable( GVarFuncs );
/* return success */
return 0;
}
/**
The second function to be called when the library is loaded by the kernel.
**/
static Int InitLibrary(StructInitInfo* module)
{
/* init filters and functions */
InitGVarFuncsFromTable( GVarFuncs );
/* return success */
return 0;
}
/**
Information about this library, returned when the library is loaded,
for example by Init__Dynamic(). This contains details of the library name,
and the further initialisation functions to call.
**/
static StructInitInfo module = {
/* type = */ MODULE_DYNAMIC,
/* name = */ "absolute value of an integer",
/* revision_c = */ 0,
/* revision_h = */ 0,
/* version = */ 0,
/* crc = */ 0,
/* initKernel = */ InitKernel,
/* initLibrary = */ InitLibrary,
/* checkInit = */ 0,
/* preSave = */ 0,
/* postSave = */ 0,
/* postRestore = */ 0
};
/**
Function called by GAP as soon as the library is dynamically loaded.
This returns the StructInitInfo data for this library
**/
StructInitInfo * Init__Dynamic (void)
{
return &module;
}
|