feisty meow concerns codebase  2.140
math_ops.h
Go to the documentation of this file.
1 #ifndef MATH_OPS_GROUP
2 #define MATH_OPS_GROUP
3 
4 /*****************************************************************************\
5 * *
6 * Name : mathematical operations *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2002-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/definitions.h>
19 
20 namespace mathematics {
21 
23 
24 class math_ops
25 {
26 public:
28  static int round_it(float to_round)
29  {
30  int to_return = int(to_round);
31  // this uses a simplistic view of rounding.
32  if (to_round - float(to_return) > 0.5) to_return++;
33  return to_return;
34  }
35 
37  static int round_it(double to_round)
38  {
39  int to_return = int(to_round);
40  // this uses a simplistic view of rounding.
41  if (to_round - double(to_return) > 0.5) to_return++;
42  return to_return;
43  }
44 
45 /*
47  static basis::u_int pow_2(const basis::u_int raise_to)
48  {
49  if (!raise_to) return 1;
50  basis::u_int to_return = 2;
51  for (basis::u_int i = 1; i < raise_to; i++)
52  to_return *= 2;
53  return to_return;
54  }
55 */
56 
58  static basis::un_int factorial(int n)
59  { return (n < 2)? 1 : n * factorial(n - 1); }
60 };
61 
62 } //namespace.
63 
64 #endif
65 
A grab-bag of mathematical functions that are frequently useful.
Definition: math_ops.h:25
static int round_it(double to_round)
returns the rounded integer value for "to_round".
Definition: math_ops.h:37
static basis::un_int factorial(int n)
returns n! (factorial), which is n * (n - 1) * (n - 2) ...
Definition: math_ops.h:58
static int round_it(float to_round)
returns the rounded integer value for "to_round".
Definition: math_ops.h:28
Constants and objects used throughout HOOPLE.
unsigned int un_int
Abbreviated name for unsigned integers.
Definition: definitions.h:62
An extension to floating point primitives providing approximate equality.
Definition: averager.h:21