/************************************************************************
*                       - INFOFLEX System -
* This source code is CONFIDENTIAL and PROPRIETARY to INFOFLEX ,
* INC. . The information contained herein may not be used, copied or
* disclosed in whole or in part except as permitted by written agreement
* signed by an officer of INFOFLEX,INC..
*
* COPYRIGHT (c) 1986 INFOFLEX , INC., BURLINGAME, CALIFORNIA.
* ALL RIGHTS RESERVED.
*************************************************************************/

/*
 * Include file: valfuncs.h
 * Description:  The value functions are used to manipulate data values of
 *		 all data types, independent of the implementation of the
 *		 decimal and money types in a particular port.
 *		 Currently all numerics are stored programmatically
 *		 (not in the database) in decimal structures (dec_t).
 */

#ifndef _VALFUNCS_H
#define _VALFUNCS_H

#ifdef UNIX 
#   ifdef VAXVMS
#       include <limits.h>
#       include <float.h>

#       define MAXSHORT   SHRT_MAX
#       define MINSHORT   SHRT_MIN
#       define MAXLONG    LONG_MAX
#       define MINLONG    LONG_MIN
#       define MAXDOUBLE  DBL_MAX
#       define MAXFLOAT   FLT_MAX
#   else
#       ifdef NOVALUEH
#           include "fxvalue.h"
#       else 
#           include <values.h>
#       endif
#       undef  MINDOUBLE
#       undef  MINFLOAT
#   endif
#endif

#ifndef MSDOS
#   ifdef NOVALUEH
#       include "fxvalue.h"
#   else 
#       include <values.h>
#   endif
#   undef  MINDOUBLE
#   undef  MINFLOAT
#   undef  MINLONG
#   undef  MINSHORT
#   define MINLONG    (-(MAXLONG-1))
#   define MINSHORT   (-(MAXSHORT-1))
#else
#   include <limits.h>
#   include <float.h>

#   if ! defined( ISDOSMSC ) || ! defined( _I_SFCSNET )
#   define MAXSHORT   SHRT_MAX
#   define MINSHORT   SHRT_MIN
#   define MAXLONG    LONG_MAX
#   define MINLONG    LONG_MIN
#   endif

#   define MAXDOUBLE  DBL_MAX
#   define MAXFLOAT   FLT_MAX
#endif
#define MINDOUBLE  -MAXDOUBLE
#define MINFLOAT   -MAXFLOAT

#ifdef NO_DEC
#define	valcvdbl(n,v)	   (v)->vlNval = (double) (n)
#else
#define	valcvdbl(n,v)	   deccvdbl( (double) (n), &(v)->vlNval)
#endif

#define valcvshort	valcvdbl
#define valcvlong	valcvdbl
#define valcvflt	valcvdbl

#ifdef NO_DEC
#define valadd(v1,v2,res)  valarith(v1,'+',v2,res)
#define valsub(v1,v2,res)  valarith(v1,'-',v2,res)
#define valmul(v1,v2,res)  valarith(v1,'*',v2,res)
#define valdiv(v1,v2,res)  valarith(v1,'/',v2,res)
#else
#define valadd(v1,v2,res)  decadd( &(v1)->vlNval, &(v2)->vlNval, &(res)->vlNval)
#define valsub(v1,v2,res)  decsub( &(v1)->vlNval, &(v2)->vlNval, &(res)->vlNval)
#define valmul(v1,v2,res)  decmul( &(v1)->vlNval, &(v2)->vlNval, &(res)->vlNval)
#define valdiv(v1,v2,res)  decdiv( &(v1)->vlNval, &(v2)->vlNval, &(res)->vlNval)
#endif

struct _S_VALUE {
	char *	vlSval;			/* pointer to string value */
	short   vlSlen;			/* maximum length of string */
#ifdef NO_DEC
	double  vlNval;			/* numbers stored in doubles */
#else
	dec_t	vlNval;			/* numbers stored in dec_t */
#endif
	short	vlType;			/* data type, in sqtypes.h */
	short	vlNull;			/* is value null? */
};
typedef struct _S_VALUE VALUE;

struct _S_LIMITS {
	char    limChar[2];
#ifdef NO_DEC
	double  limDouble;
	float	limFloat;
	long	limLong;
	short	limShort;
#else
	dec_t	limDec;
	dec_t	limSmflt;
	dec_t	limLong;
	dec_t	limShort;
#endif
};
typedef struct _S_LIMITS LIMITS;

#define VALNULL	(VALUE *)0

#ifdef NOTUSED
extern VALUE maxval;
extern VALUE minval;

extern double valtodbl();
extern float valtoflt();
extern long valtolong();
extern short valtoshort();
#endif

#endif /* _VALFUNCS_H */
