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:
27  typedef signed long long fat_int;
28 //hmmm: get this definition (or a better named one) into our definitions header.
29 
31  static fat_int round_it(float to_round)
32  {
33  fat_int to_return = fat_int(to_round);
34  // this uses a simplistic view of rounding.
35  if (to_round - float(to_return) > 0.5) to_return++;
36  return to_return;
37  }
38 
40  static fat_int round_it(double to_round)
41  {
42  fat_int to_return = fat_int(to_round);
43  // this uses a simplistic view of rounding.
44  if (to_round - double(to_return) > 0.5) to_return++;
45  return to_return;
46  }
47 
48 /*
50  static basis::u_int pow_2(const basis::u_int raise_to)
51  {
52  if (!raise_to) return 1;
53  basis::u_int to_return = 2;
54  for (basis::u_int i = 1; i < raise_to; i++)
55  to_return *= 2;
56  return to_return;
57  }
58 */
59 
61  static basis::un_int factorial(int n)
62  { return (n < 2)? 1 : n * factorial(n - 1); }
63 };
64 
65 } //namespace.
66 
67 #endif
68 
A grab-bag of mathematical functions that are frequently useful.
Definition: math_ops.h:25
signed long long fat_int
Definition: math_ops.h:27
static fat_int round_it(float to_round)
returns the rounded integer value for "to_round".
Definition: math_ops.h:31
static basis::un_int factorial(int n)
returns n! (factorial), which is n * (n - 1) * (n - 2) ...
Definition: math_ops.h:61
static fat_int round_it(double to_round)
returns the rounded integer value for "to_round".
Definition: math_ops.h:40
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