Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GAP_IsChar, GAP_IsBoolean, GAP_IsFunction; fix GAP_IsMacFloat; expand some comments #5457

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/libgap-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,25 @@ Obj GAP_MOD(Obj a, Obj b)
//// booleans
////

int GAP_IsBoolean(Obj obj)
{
return obj && TNUM_OBJ(obj) == T_BOOL;
}

Obj GAP_True;
Obj GAP_False;
Obj GAP_Fail;


////
//// calls
//// functions and calls
////

int GAP_IsFunction(Obj obj)
{
return obj && IS_FUNC(obj);
}

Obj GAP_CallFuncList(Obj func, Obj args)
{
return CallFuncList(func, args);
Expand Down Expand Up @@ -313,9 +323,9 @@ Obj GAP_CallFunc3Args(Obj func, Obj a1, Obj a2, Obj a3)
//// floats
////

Int GAP_IsMacFloat(Obj obj)
int GAP_IsMacFloat(Obj obj)
{
return IS_MACFLOAT(obj);
return obj && IS_MACFLOAT(obj);
}

double GAP_ValueMacFloat(Obj obj)
Expand Down Expand Up @@ -564,6 +574,16 @@ char * GAP_CSTR_STRING(Obj string)
return CSTR_STRING(string);
}


////
//// chars
////

int GAP_IsChar(Obj obj)
{
return obj && TNUM_OBJ(obj) == T_CHAR;
}

Int GAP_ValueOfChar(Obj obj)
{
if (TNUM_OBJ(obj) != T_CHAR) {
Expand Down
50 changes: 48 additions & 2 deletions src/libgap-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,25 @@ Obj GAP_MOD(Obj a, Obj b);
//// booleans
////

// Returns 1 if <obj> is a GAP boolean, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsBoolean(Obj obj);

extern Obj GAP_True;
extern Obj GAP_False;
extern Obj GAP_Fail;


////
//// calls
//// functions and calls
////

// Returns 1 if <obj> is a GAP function, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsFunction(Obj obj);

// Call the GAP object <func> as a function with arguments given
// as a GAP list <args>.
Obj GAP_CallFuncList(Obj func, Obj args);
Expand All @@ -319,7 +329,9 @@ Obj GAP_CallFunc3Args(Obj func, Obj a1, Obj a2, Obj a3);
////

// Returns 1 if <obj> is a GAP machine float, 0 if not.
Int GAP_IsMacFloat(Obj obj);
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsMacFloat(Obj obj);

// Returns the value of the GAP machine float object <obj>.
// If <obj> is not a machine float object, an error is raised.
Expand All @@ -334,12 +346,18 @@ Obj GAP_NewMacFloat(double x);
////

// Returns 1 if <obj> is a GAP integer, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsInt(Obj obj);

// Returns 1 if <obj> is a GAP small (aka immediate) integer, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsSmallInt(Obj obj);

// Returns 1 if <obj> is a GAP large integer, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsLargeInt(Obj obj);


Expand All @@ -355,6 +373,8 @@ int GAP_IsLargeInt(Obj obj);
Obj GAP_MakeObjInt(const UInt * limbs, Int size);

// Return a GAP integer object with value equal to <val>.
//
// Never raises an error.
Obj GAP_NewObjIntFromInt(Int val);

// Return an integer equal to the given GAP integer object. If <obj> is not
Expand Down Expand Up @@ -387,6 +407,8 @@ const UInt * GAP_AddrInt(Obj obj);
////

// Returns 1 if <obj> is a GAP list, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsList(Obj obj);

// Returns the length of the given GAP list.
Expand Down Expand Up @@ -433,12 +455,18 @@ Obj GAP_NewRange(Int len, Int low, Int inc);
// `GAP_IsMatrixObj` checks for special cases that are not plain lists.

// Returns 1 if <obj> is a GAP matrix or matrix obj, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsMatrixOrMatrixObj(Obj obj);

// Returns 1 if <obj> is a GAP matrix, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsMatrix(Obj obj);

// Returns 1 if <obj> is a GAP matrix obj, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsMatrixObj(Obj obj);

// Returns the number of rows of the given GAP matrix or matrix obj.
Expand Down Expand Up @@ -466,6 +494,8 @@ Obj GAP_ElmMat(Obj mat, UInt row, UInt col);
////

// Returns 1 if <obj> is a GAP record, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsRecord(Obj obj);

// Assign <val> to component given by <name> in the GAP record <rec>.
Expand All @@ -487,6 +517,8 @@ Obj GAP_NewPrecord(Int capacity);
////

// Returns 1 if <obj> is a GAP string, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsString(Obj obj);

// Returns the length of the given GAP string.
Expand Down Expand Up @@ -524,11 +556,25 @@ Obj GAP_MakeStringWithLen(const char * string, UInt len);
// terminated C string.
Obj GAP_MakeImmString(const char * string);


////
//// chars
////

// Returns 1 if <obj> is a GAP char, 0 if not.
//
// Never raises an error. Safe to be called with a NULL pointer.
int GAP_IsChar(Obj obj);

// Returns the value of the GAP character object <obj>.
// If <obj> is not a GAP character object, it returns -1.
//
// Never raises an error.
Int GAP_ValueOfChar(Obj obj);

// Returns the GAP character object with value <obj>.
//
// Never raises an error.
Obj GAP_CharWithValue(UChar obj);

#ifdef __cplusplus
Expand Down