Flatland

Documentation

SourceForge.net Logo

vector.cpp

Go to the documentation of this file.
00001 // Summary: Defines vec2 methods.
00002 // Copyright: 2007  Philip Rideout.  All rights reserved.
00003 // License: see bsd-license.txt
00004 
00005 #include <flatland/vector.hpp>
00006 #include <math.h>
00007 
00008 using namespace Flatland;
00009 
00010 const float d2r = pi / 180;
00011 
00012 vec2 vec2::rotate(float d) const { return rotate(vec2(cosf(d2r * d), sinf(d2r * d))); }
00013 float vec2::length() const { return sqrtf(dot(*this, *this)); }
00014 
00015 // returns true for IEEE floats that are infinity or a not-a-number
00016 bool Flatland::is_nan(float f)
00017 {
00018     unsigned long bits = *((unsigned long*) &f);
00019 
00020     // quiet -NaN
00021     if (bits >= 0xffc00001 && bits <= 0xffffffff) return true;
00022     
00023     // indeterminate
00024     if (bits == 0xffc00000) return true;
00025 
00026     // signaling -NaN
00027     if (bits >= 0xff800001 && bits <= 0xffbfffff) return true;
00028 
00029     // minus infinity
00030     if (bits == 0xff800000) return true;
00031 
00032     // positive infinity
00033     if (bits == 0x7f800000) return true;
00034 
00035     // signaling +NaN
00036     if (bits >= 0x7f800001 && bits <= 0x7fbfffff) return true;
00037 
00038     // signaling +NaN
00039     if (bits >= 0x7fc00000 && bits <= 0x7fffffff) return true;
00040 
00041     return false;
00042 }
00043 
00044 float Flatland::round(float f)
00045 {
00046     return (float) ((int) (f + 0.5f));
00047 }

Generated on Sat Jan 13 17:20:21 2007 for Flatland by doxygen 1.5.1