00001 /* 00002 * This file is part of the ESO SINFONI Pipeline 00003 * Copyright (C) 2004,2005 European Southern Observatory 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program 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 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA 00018 */ 00019 #ifdef HAVE_CONFIG_H 00020 # include <config.h> 00021 #endif 00022 /* 00023 * This function is so generic and used everywhere, it diserves its 00024 * own source file... 00025 */ 00026 /* 00027 $Id: sinfo_ipow.c,v 1.4 2012/03/02 08:42:20 amodigli Exp $ 00028 $Author: amodigli $ 00029 $Date: 2012/03/02 08:42:20 $ 00030 $Revision: 1.4 $ 00031 */ 00053 #include "sinfo_ipow.h" 00054 double sinfo_ipow(double x, int p) 00055 { 00056 double r, recip ; 00057 00058 /* Get rid of trivial cases */ 00059 switch (p) { 00060 case 0: 00061 return 1.00 ; 00062 00063 case 1: 00064 return x ; 00065 00066 case 2: 00067 return x*x ; 00068 00069 case 3: 00070 return x*x*x ; 00071 00072 case -1: 00073 return 1.00 / x ; 00074 00075 case -2: 00076 return (1.00 / x) * (1.00 / x) ; 00077 } 00078 if (p>0) { 00079 r = x ; 00080 while (--p) r *= x ; 00081 } else { 00082 r = recip = 1.00 / x ; 00083 while (++p) r *= recip ; 00084 } 00085 return r; 00086 } 00087 00088