メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

lo-mappers.cc

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <cfloat>
00028 #include <cmath>
00029 
00030 #if defined (HAVE_SUNMATH_H)
00031 #include <sunmath.h>
00032 #endif
00033 
00034 #include "lo-error.h"
00035 #include "lo-ieee.h"
00036 #include "lo-mappers.h"
00037 #include "lo-specfun.h"
00038 #include "lo-utils.h"
00039 #include "oct-cmplx.h"
00040 
00041 #include "f77-fcn.h"
00042 
00043 #ifndef M_LOG10E
00044 #define M_LOG10E 0.43429448190325182765
00045 #endif
00046 
00047 // double -> double mappers.
00048 
00049 double
00050 arg (double x)
00051 {
00052   return atan2 (0.0, x);
00053 }
00054 
00055 double
00056 conj (double x)
00057 {
00058   return x;
00059 }
00060 
00061 double
00062 fix (double x)
00063 {
00064   return x > 0 ? floor (x) : ceil (x);
00065 }
00066 
00067 double
00068 imag (double)
00069 {
00070   return 0.0;
00071 }
00072 
00073 double
00074 real (double x)
00075 {
00076   return x;
00077 }
00078 
00079 double
00080 xround (double x)
00081 {
00082 #if defined (HAVE_ROUND)
00083   return round (x);
00084 #else
00085   return x > 0 ? floor (x + 0.5) : ceil (x - 0.5);
00086 #endif
00087 }
00088 
00089 double
00090 signum (double x)
00091 {
00092   double tmp = 0.0;
00093 
00094   if (x < 0.0)
00095     tmp = -1.0;
00096   else if (x > 0.0)
00097     tmp = 1.0;
00098 
00099   return xisnan (x) ? octave_NaN : tmp;
00100 }
00101 
00102 // double -> bool mappers.
00103 
00104 bool
00105 xisnan (double x)
00106 {
00107   return lo_ieee_isnan (x);
00108 }
00109 
00110 bool
00111 xfinite (double x)
00112 {
00113   return lo_ieee_finite (x);
00114 }
00115 
00116 bool
00117 xisinf (double x)
00118 {
00119   return lo_ieee_isinf (x);
00120 }
00121 
00122 bool
00123 octave_is_NA (double x)
00124 {
00125   return lo_ieee_is_NA (x);
00126 }
00127 
00128 bool
00129 octave_is_NaN_or_NA (double x)
00130 {
00131   return lo_ieee_is_NaN_or_NA (x);
00132 }
00133 
00134 // (double, double) -> double mappers.
00135 
00136 // XXX FIXME XXX -- need to handle NA too?
00137 
00138 double
00139 xmin (double x, double y)
00140 {
00141   if (x < y)
00142     return x;
00143 
00144   if (y <= x)
00145     return y;
00146 
00147   if (octave_is_NaN_or_NA (x) && ! octave_is_NaN_or_NA (y))
00148     return y;
00149   else if (octave_is_NaN_or_NA (y) && ! octave_is_NaN_or_NA (x))
00150     return x;
00151   else if (octave_is_NA (x) || octave_is_NA (y))
00152     return octave_NA;
00153   else
00154     return octave_NaN;
00155 }
00156 
00157 double
00158 xmax (double x, double y)
00159 {
00160   if (x > y)
00161     return x;
00162 
00163   if (y >= x)
00164     return y;
00165 
00166   if (octave_is_NaN_or_NA (x) && ! octave_is_NaN_or_NA (y))
00167     return y;
00168   else if (octave_is_NaN_or_NA (y) && ! octave_is_NaN_or_NA (x))
00169     return x;
00170   else if (octave_is_NA (x) || octave_is_NA (y))
00171     return octave_NA;
00172   else
00173     return octave_NaN;
00174 }
00175 
00176 // complex -> complex mappers.
00177 
00178 Complex
00179 acos (const Complex& x)
00180 {
00181   static Complex i (0, 1);
00182 
00183   return (real (x) * imag (x) < 0.0) ? i * acosh (x) : -i * acosh (x);
00184 }
00185 
00186 Complex
00187 acosh (const Complex& x)
00188 {
00189   return log (x + sqrt (x*x - 1.0));
00190 }
00191 
00192 Complex
00193 asin (const Complex& x)
00194 {
00195   static Complex i (0, 1);
00196 
00197   return -i * log (i*x + sqrt (1.0 - x*x));
00198 }
00199 
00200 Complex
00201 asinh (const Complex& x)
00202 {
00203   return log (x + sqrt (x*x + 1.0));
00204 }
00205 
00206 Complex
00207 atan (const Complex& x)
00208 {
00209   static Complex i (0, 1);
00210 
00211   return i * log ((i + x) / (i - x)) / 2.0;
00212 }
00213 
00214 Complex
00215 atanh (const Complex& x)
00216 {
00217   return log ((1.0 + x) / (1.0 - x)) / 2.0;
00218 }
00219 
00220 #if !defined (CXX_ISO_COMPLIANT_LIBRARY)
00221 
00222 Complex
00223 log10 (const Complex& x)
00224 {
00225   return M_LOG10E * log (x);
00226 }
00227 
00228 Complex
00229 tan (const Complex& x)
00230 {
00231   return sin (x) / cos (x);
00232 }
00233 
00234 Complex
00235 tanh (const Complex& x)
00236 {
00237   return sinh (x) / cosh (x);
00238 }
00239 
00240 #endif
00241 
00242 Complex
00243 ceil (const Complex& x)
00244 {
00245   return Complex (ceil (real (x)), ceil (imag (x)));
00246 }
00247 
00248 Complex
00249 fix (const Complex& x)
00250 {
00251   return Complex (fix (real (x)), fix (imag (x)));
00252 }
00253 
00254 Complex
00255 floor (const Complex& x)
00256 {
00257   return Complex (floor (real (x)), floor (imag (x)));
00258 }
00259 
00260 Complex
00261 xround (const Complex& x)
00262 {
00263   return Complex (xround (real (x)), xround (imag (x)));
00264 }
00265 
00266 Complex
00267 signum (const Complex& x)
00268 {
00269   return x / abs (x);
00270 }
00271 
00272 // complex -> bool mappers.
00273 
00274 bool
00275 xisnan (const Complex& x)
00276 {
00277   return (xisnan (real (x)) || xisnan (imag (x)));
00278 }
00279 
00280 bool
00281 xfinite (const Complex& x)
00282 {
00283   double rx = real (x);
00284   double ix = imag (x);
00285 
00286   return (xfinite (rx) && ! octave_is_NaN_or_NA (rx)
00287           && xfinite (ix) && ! octave_is_NaN_or_NA (ix));
00288 }
00289 
00290 bool
00291 xisinf (const Complex& x)
00292 {
00293   return (xisinf (real (x)) || xisinf (imag (x)));
00294 }
00295 
00296 bool
00297 octave_is_NA (const Complex& x)
00298 {
00299   return (octave_is_NA (real (x)) || octave_is_NA (imag (x)));
00300 }
00301 
00302 bool
00303 octave_is_NaN_or_NA (const Complex& x)
00304 {
00305   return (octave_is_NaN_or_NA (real (x)) || octave_is_NaN_or_NA (imag (x)));
00306 }
00307 
00308 // (complex, complex) -> complex mappers.
00309 
00310 // XXX FIXME XXX -- need to handle NA too?
00311 
00312 Complex
00313 xmin (const Complex& x, const Complex& y)
00314 {
00315   return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y);
00316 }
00317 
00318 Complex
00319 xmax (const Complex& x, const Complex& y)
00320 {
00321   return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y);
00322 }
00323 
00324 /*
00325 ;;; Local Variables: ***
00326 ;;; mode: C++ ***
00327 ;;; End: ***
00328 */

Wed Dec 29 11:51:39 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送