math_ops.h

Go to the documentation of this file.
00001 #ifndef MATH_OPS_GROUP
00002 #define MATH_OPS_GROUP
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : mathematical operations                                           *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2002-$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 
00019 
00020 class math_ops
00021 {
00022 public:
00024   static int round_it(float to_round)
00025   {
00026     int to_return = int(to_round);
00027     // this uses a simplistic view of rounding.
00028     if (to_round - float(to_return) > 0.5) to_return++;
00029     return to_return;
00030   }
00031 
00033   static int round_it(double to_round)
00034   {
00035     int to_return = int(to_round);
00036     // this uses a simplistic view of rounding.
00037     if (to_round - double(to_return) > 0.5) to_return++;
00038     return to_return;
00039   }
00040 
00042   static u_int pow_2(const u_int raise_to)
00043   {
00044     if (!raise_to) return 1;
00045     u_int to_return = 2;
00046     for (u_int i = 1; i < raise_to; i++)
00047       to_return *= 2;
00048     return to_return;
00049   }
00050 
00052   static u_int factorial(int n)
00053   { return (n < 2)? 1 : n * factorial(n - 1); }
00054 };
00055 
00056 #endif
00057 

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