Home

Download

Features

Screenshots

Handbook

Browse Source

Authors

SourceForge.net Logo
Hosted by SourceForge.net

OSI Certified


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Search  

fungmath.cpp

00001 /***************************************************************************
00002                           fungmath.h  -  description
00003                              -------------------
00004     begin                : Mon May 12 2003
00005     copyright            : (C) 2003 by Fungmeista
00006     email                : mizunoami44@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include "fungmath.h"
00018  
00019 #include <cmath>
00020 #include <ctime>
00021 #include <cstdlib>
00022 
00023 int num_digits( int i )
00024 {
00025     int n = i / 10;
00026     if ( n == 0 )
00027         return 1;
00028     else
00029         return num_digits( n );
00030     
00031 }
00032 
00033 int fibonacci( unsigned int n )
00034 {
00035     if ( n == 0)
00036         return 0;
00037     else if ( n == 1 )
00038         return 1;
00039     else
00040         return fibonacci( n - 1 ) + fibonacci( n - 2 );
00041 }
00042 
00043 int factorial( unsigned int n )
00044 {
00045     if ( n == 0 )
00046         return 1;
00047     else
00048         return factorial( n - 1 ) * n;
00049 }
00050 
00051 int iRand( float low, float high )
00052 {
00053     return (rand() % static_cast<int>(ROUND(high-low-1)))+static_cast<int>(ROUND(low)) + 1;
00054 }
00055 
00056 float fRand( float low, float high )
00057 {
00058     return static_cast<float>(rand())/static_cast<float>(RAND_MAX) * (high-low) + low;
00059 }
00060 
00061 
00062