Newer
Older
Import / research / 3d-octrees / jLimits.h
/*
 * =====================================================================================
 *
 *       Filename:  jLimits.h
 *
 *    Description:  Limits of the types in jTypes
 *
 *        Version:  1.0
 *        Created:  04/06/2011 08:10:27
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  John Ryland (jryland), jryland@xiaofrog.com
 *        Company:  InvertedLogic
 *
 * =====================================================================================
 */

#ifndef __J_LIMITS_H__
#define __J_LIMITS_H__


#include <limits.h>


// I guess this might depend on the C libraries and/or compiler
#if UINT_MAX < 4294967296       // is the number less or more than what can fit in 32 bits
#  if UINT_MAX < 65536          // is it more than will fit in 16 bits
#    define INT_BITS        16  // lets assume an int is 16 bits or more
#  else
#    define INT_BITS        32  // UINT_MAX is between 65536 and 4294967296, guess it it 32 bits
#  endif
#else
#  define INT_BITS          64  // its going to be more than 32 bits so guess it is 64 bits
#endif


#include <assert.h>
class VerifyIntBitSize
{
public:
    VerifyIntBitSize() { assert(sizeof(int)*8 == INT_BITS); }
};
VerifyIntBitSize verifyIntBits;


#define J_INT8_MIN          SCHAR_MIN
#define J_INT8_MAX          SCHAR_MAX
#define J_INT16_MIN         SHRT_MIN
#define J_INT16_MAX         SHRT_MAX
#define J_INT32_MIN         INT_MIN
#define J_INT32_MAX         INT_MAX
#define J_INT64_MIN         LLONG_MIN
#define J_INT64_MAX         LLONG_MAX


#define J_UINT8_MIN         0
#define J_UINT8_MAX         UCHAR_MAX
#define J_UINT16_MIN        0 
#define J_UINT16_MAX        USHRT_MAX
#define J_UINT32_MIN        0 
#define J_UINT32_MAX        UINT_MAX
#define J_UINT64_MIN        0 
#define J_UINT64_MAX        ULLONG_MAX


#define J_FLOAT32_MIN       -FLT_MAX 
#define J_FLOAT32_MAX       FLT_MIN
#define J_FLOAT64_MIN       -DBL_MAX
#define J_FLOAT64_MAX       DBL_MAX


#endif // __J_LIMITS_H__