math_bits.h

Go to the documentation of this file.
00001 #ifndef MATHEMATICAL_OPERATIONS_GROUP
00002 #define MATHEMATICAL_OPERATIONS_GROUP
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : mathematical operations group                                     *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1996-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00022 #include "geometric_dll.h"
00023 
00024 #include <basis/istring.h>
00025 
00026 istring GEOMETRIC_FUNCTION_STYLE crop_numeric(const istring &input);
00028 
00033 istring GEOMETRIC_FUNCTION_STYLE crop_non_numeric(const istring &input);
00035 
00036 // type identification functions:
00037 
00039 
00041 template <class numeric_type>
00042 bool is_floating_point(numeric_type t)
00043     { t = numeric_type(5.1); t = numeric_type(t * 3.0);
00044           return 0.001 < float(absolute_value(numeric_type(t - 15.0))); }
00045 
00047 template <class numeric_type>
00048 bool is_integral(numeric_type t) { return !is_floating_point(t); }
00049 
00050 // the following functions (is_short, is_signed and is_unsigned) are only
00051 // useful for integral types.
00052 
00054 template <class numeric_type>
00055 bool is_short(numeric_type) { return sizeof(numeric_type) == 2; }
00056 
00058 template <class numeric_type>
00059 bool is_unsigned(numeric_type t) { t = -1; return t > 0; }
00061 template <class numeric_type>
00062 bool is_signed(numeric_type t) { return !is_unsigned(t); }
00063 
00065 
00068 template <class numeric_type>
00069 istring numeric_specifier(numeric_type t) {
00070   istring to_return("%d");
00071   if (is_floating_point(t))
00072     to_return = istring("%f");
00073   else {  // integral.
00074     if (is_unsigned(t))
00075       to_return = istring("%u");
00076     if (is_short(t))
00077       to_return.insert(1, "h");
00078   }
00079   return to_return;
00080 }
00081 
00082 #endif // outer guard.
00083 

Generated on Fri Nov 28 04:29:14 2008 for HOOPLE Libraries by  doxygen 1.5.1