diff --git a/include/xchange.h b/include/xchange.h index 6ee5c8b..c4edc56 100644 --- a/include/xchange.h +++ b/include/xchange.h @@ -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); diff --git a/src/xchange.c b/src/xchange.c index a47a325..80069d4 100644 --- a/src/xchange.c +++ b/src/xchange.c @@ -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.