last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2004 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 00042 /** 00043 * \file cvrRound.h 00044 * Definition of some usually used global functions for 00045 * mathematical rounding (round, iround, lround and cround_cast) 00046 * \author Pablo Alvarado 00047 * \date 28.04.1999 00048 * 00049 * $Id: cvrRound.h,v 1.3 2004/07/27 08:22:42 alvarado Exp $ 00050 */ 00051 00052 #ifndef _CVR_ROUND_H_ 00053 #define _CVR_ROUND_H_ 00054 00055 namespace cvr { 00056 00057 /** 00058 * Round any float type mathematicly 00059 * 00060 * @ingroup gBasicMathFunc 00061 */ 00062 template<typename T> 00063 inline T round(T x); 00064 00065 /** 00066 * Round any float type mathematicly and return an integer 00067 * 00068 * @ingroup gBasicMathFunc 00069 */ 00070 template<typename T> 00071 inline int iround(T x); 00072 00073 /** 00074 * Round any float type mathematicly and return an long integer 00075 * 00076 * @ingroup gBasicMathFunc 00077 */ 00078 template<typename T> 00079 inline long lround(T x); 00080 00081 /** 00082 * Conditional round cast. 00083 * 00084 * This template functions cast the given value using rounding if necessary. 00085 * This means, if you cast between different floating point types, no 00086 * integer rounding will be done, but if you cast from a floating point 00087 * value to an integer value, the result will be rounded. For example: 00088 * 00089 * \code 00090 * int i = cround_cast<int>(3.6); // i will contain 4 00091 * float f = cround_cast<float>(3.6); // i will contain 3.6f 00092 * \endcode 00093 * 00094 * This sort of casting is used in the implementation of several template 00095 * functions where the output type depends on the current instantiation. 00096 */ 00097 template<typename T,typename F> 00098 inline T cround_cast(const F from); 00099 00100 } 00101 00102 #include "cvrRound_inline.h" 00103 00104 #endif