libidx
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Yann LeCun and Pierre Sermanet * 00003 * yann@cs.nyu.edu, pierre.sermanet@gmail.com * 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Redistribution under a license not approved by the Open Source 00013 * Initiative (http://www.opensource.org) must display the 00014 * following acknowledgement in all advertising material: 00015 * This product includes software developed at the Courant 00016 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00017 * * The names of the authors may not be used to endorse or promote products 00018 * derived from this software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00021 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00024 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00027 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 ***************************************************************************/ 00031 00032 #ifndef NUMERICS_HPP_ 00033 #define NUMERICS_HPP_ 00034 00035 namespace ebl { 00036 00038 00039 template <typename T> 00040 T limits<T>::max() { 00041 #ifdef __NOSTL__ 00042 eblerror("limits::max not implemented for this type"); 00043 #else 00044 return (std::numeric_limits<T>::max)(); 00045 #endif 00046 } 00047 00048 template <typename T> 00049 T limits<T>::min() { 00050 #ifdef __NOSTL__ 00051 eblerror("limits::min not implemented for this type"); 00052 #else 00053 return (std::numeric_limits<T>::min)(); 00054 #endif 00055 } 00056 00057 template <typename T> template <typename T2> 00058 T saturator<T>::saturate (T2 in) { 00059 if (in > limits<T>::max()) 00060 return limits<T>::max(); 00061 else if (in < limits<T>::min()) 00062 return limits<T>::min(); 00063 else 00064 return (T)in; 00065 } 00066 00067 template <typename T> 00068 T angle_distance(T a1, T a2) { 00069 double d = (double) a1 - (double) a2; 00070 double fd = fabs(d); 00071 if (fd < TWOPI - fd) 00072 return (T) d; 00073 else { 00074 if (d < 0) 00075 return (T) (TWOPI - fd); 00076 else 00077 return (T) (fd - TWOPI); 00078 } 00079 } 00080 00081 #define saturate(in, T) (saturator<T>::saturate(in)) 00082 00083 } // end namespace ebl 00084 00085 #endif /* NUMERICS_HPP_ */