00001 /* 00002 * Copyright 2008, 2009 Alexandros Frantzis, Michael Iatrou 00003 * 00004 * This file is part of libbls. 00005 * 00006 * libbls is free software: you can redistribute it and/or modify it under the 00007 * terms of the GNU Lesser General Public License as published by the Free Software 00008 * Foundation, either version 3 of the License, or (at your option) any later 00009 * version. 00010 * 00011 * libbls is distributed in the hope that it will be useful, but WITHOUT ANY 00012 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00014 * details. 00015 * 00016 * You should have received a copy of the GNU General Public License along with 00017 * libbls. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 /** 00021 * @file type_limits.h 00022 * 00023 * Macros to get the limits of types. 00024 */ 00025 #ifndef _TYPE_LIMITS_H 00026 #define _TYPE_LIMITS_H 00027 00028 /* These were taken from http://www.fefe.de/intof.html */ 00029 00030 #define __HALF_MAX_SIGNED(type) ((type)1 << (sizeof(type)*8-2)) 00031 #define __MAX_SIGNED(type) (__HALF_MAX_SIGNED(type) - 1 + __HALF_MAX_SIGNED(type)) 00032 #define __MIN_SIGNED(type) (-1 - __MAX_SIGNED(type)) 00033 00034 #define __MIN(type) ((type)-1 < 1?__MIN_SIGNED(type):(type)0) 00035 #define __MAX(type) ((type)~__MIN(type)) 00036 00037 #endif