ShHalf.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
00018 // MA  02110-1301, USA
00020 #ifndef SHHALF_HPP
00021 #define SHHALF_HPP
00022 
00023 #include <limits>
00024 #include "ShUtility.hpp"
00025 
00026 namespace SH {
00027 
00028 struct ShHalf {
00029   typedef unsigned short T; 
00030 
00031   static const int S = 1 << 15; // sign bit
00032   static const int E = 1 << 10; // exponent 
00033 
00034   T m_val;
00035 
00037   ShHalf();
00038 
00040   ShHalf(double value); 
00041 
00042   operator double() const;
00043 
00045   ShHalf& operator=(double value);
00046   ShHalf& operator=(const ShHalf& other);
00047   ShHalf& operator+=(double value);
00048   ShHalf& operator+=(const ShHalf& other);
00049   ShHalf& operator-=(double value);
00050   ShHalf& operator-=(const ShHalf& other);
00051   ShHalf& operator*=(double value);
00052   ShHalf& operator*=(const ShHalf& other);
00053   ShHalf& operator/=(double value);
00054   ShHalf& operator/=(const ShHalf& other);
00055 
00058   ShHalf& operator%=(double value);
00059   ShHalf& operator%=(const ShHalf& other);
00060   // @}
00061 
00063   ShHalf operator-() const;
00064 
00066   friend std::ostream& operator<<(std::ostream& out, const ShHalf &value);
00067 
00068 
00070   friend std::istream& operator>>(std::istream& out, ShHalf &value);
00071 
00072   private:
00074     static ShHalf make_half(T value);
00075 
00076     static T to_val(double value);
00077     void set_val(double value);
00078     double get_double() const;
00079 };
00080 
00081 }
00082 
00083 #include "ShHalfImpl.hpp"
00084   
00085 #endif

Generated on Wed Nov 9 15:29:32 2005 for Sh by  doxygen 1.4.5