Skip to content

Commit

Permalink
Add xIsInteger(), xIsDecimal(), xIsNumeric() type inspection functions
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed Jan 2, 2025
1 parent 47321fd commit 9715aa2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/xchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ int xPrintDims(char *dst, int ndim, const int *sizes);
// Low-level utilities ---------------------------------------->
char xTypeChar(XType type);
boolean xIsCharSequence(XType type);
boolean xIsInteger(XType type);
boolean xIsDecimal(XType type);
boolean xIsNumeric(XType type);
char *xLastSeparator(const char *id);
char *xNextIDToken(const char *id);
char *xCopyIDToken(const char *id);
Expand Down
54 changes: 52 additions & 2 deletions src/xchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,65 @@ void xSetDebug(boolean value) {
/**
* Checks if the type represents a fixed-size character / binary sequence.
*
* \param type X-Change type to check.
* \param type xchange type to check.
*
* \return TRUE if it is a type for a (fixed size) character array, otherwise FALSE.
* \return TRUE (1) if it is a type for a (fixed size) character array, otherwise FALSE (0).
*
*/
boolean xIsCharSequence(XType type) {
return type < 0;
}

/**
* Checks if the type represents a signed integer value of any width.
*
* @param type xchange type to check.
* @return TRUE (1) if the type is for an integer value, or else FALSE (0)
*
* @sa xIsDecimal()
* @sa xIsNumeric()
* @sa xGetAsLong()
*/
boolean xIsInteger(XType type) {
switch(type) {
case X_BOOLEAN :
case X_BYTE :
case X_SHORT :
case X_INT :
case X_LONG :
return TRUE;
default:
return FALSE;
}
}

/**
* Checks if the type represents a floating-point value of any width.
*
* @param type xchange type to check.
* @return TRUE (1) if the type is for a floating-point value, or else FALSE (0)
*
* @sa xIsInteger()
* @sa xIsNumeric()
* @sa xGetAsDouble()
*/
boolean xIsDecimal(XType type) {
return (type == X_FLOAT || type == X_DOUBLE);
}

/**
* Checks if the type represents a numerical value.
*
* @param type xchange type to check.
* @return TRUE (1) if the type is for a number value, or else FALSE (0)
*
* @sa xIsInteger()
* @sa xIsDecimal()
*/
boolean xIsNumeric(XType type) {
return (xIsInteger(type) || xIsDecimal(type));
}

/**
* Returns the number of characters, including a '\0' termination that a single element of the
* might be expected to fill.
Expand Down

0 comments on commit 9715aa2

Please sign in to comment.