Example 3

This program is the same as Example 2 except is uses pseudo-functions
defined in Number.h to simplify the C source code.


/***
* Number.c
*
* By: Scott McIntosh, Nantucket Corp.
*
* This function is identical to Number.c in Example2 except that it
* uses the pseudo-functions ISFLOAT(), ISLONG(), and ISINT() which are
* defined in Number.h
*
* Compile: cl /AL /c /FPa /Gs /Oalt /Zl number.c
* Link: RTLINK FI numtest, number LIB clipper, llibca /NOE
*/

#include "extend.h"
#include "number.h"

CLIPPER NUMBER( void )
{
double dNum;
long lNum;
int iNum;

dNum = _parnd(1);
lNum = _parnl(1);
iNum = _parni(1);

if( ISFLOAT(1) )
{
cprintf( "\r\n\n Double " );
_retnd( dNum );
}

if( ISINT(1) )
{
cprintf( "\r\n\n Integer " );
_retni( iNum );
}

if( ISLONG(1) )
{
cprintf( "\r\n\n Long " );
_retnl( lNum );
}
return;
}


/* EOF: Example 3 */

/***
* Declares extend.h style pseudo-functions (like ISCHAR() or ISNUM() )
* to check the C data type for a number.
*/

#include <limits.h>


/* macro to determine if a number is within the range of an integer */
#define INTRANGE(n) ( ( n >= INT_MIN ) && ( n <= INT_MAX ) )

/* macros to test for each C numeric data type */
#define ISFLOAT(n) ( (_parnd(n) - (double) _parnl(n) ) != 0.0 )
#define ISINT(n) ( !ISFLOAT(n) && INTRANGE( _parnl(n) ) )
#define ISLONG(n) ( !ISFLOAT(n) && !ISINT(n) )


/* EOF: Number.h */