Math.hpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #ifndef Math_hpp
00023 #define Math_hpp
00024 
00025 namespace se_core {
00026     class _SeCoreExport Math {
00027     public:
00028         static short random(short max) {
00029             static short seed = 1025;
00030             seed = ~((seed + 254) * 11) / 3;
00031             return (seed < 0 ? -seed : seed) % max;
00032         }
00033 
00034         static long sqrt(long v) {
00035             // Highest max that will prevent overflow
00036             long max = 0x7fff;
00037             long min = 0;
00038             while(max > min + 1) {
00039                 long middle = (max + min) >> 1;
00040                 if(middle * middle < v)
00041                     min = middle;
00042                 else
00043                     max = middle;
00044             }
00045             return max;
00046         }
00047 
00048         /*
00049         static size_t hashCode(size_t size, const void* ptr) {
00050             // idea is from Bjarne Stroustrup 3rd $17.6.2.3
00051             size_t res = 0;
00052             const char* p = (const char*)ptr;  // reinterpret_cast
00053             while (size--)
00054                 res = (res << 1) ^ *p++;
00055             return res;
00056         }
00057         */
00058 
00059     };
00060 
00061 }
00062 
00063 #endif

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo