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

lo-ieee.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_FLOATINGPOINT_H)
00031 #include <floatingpoint.h>
00032 #endif
00033 
00034 #if defined (HAVE_IEEEFP_H)
00035 #include <ieeefp.h>
00036 #endif
00037 
00038 #if defined (HAVE_NAN_H)
00039 #if defined (SCO)
00040 #define _IEEE 1
00041 #endif
00042 #include <nan.h>
00043 #if defined (SCO)
00044 #undef _IEEE
00045 #endif
00046 #endif
00047 
00048 #include "lo-error.h"
00049 #include "lo-ieee.h"
00050 #include "mach-info.h"
00051 
00052 void
00053 octave_ieee_init (void)
00054 {
00055   // Default values.  DBL_MAX is not right for NaN and NA, but do you
00056   // have a better suggestion?  If you don't have IEEE floating point
00057   // values, there are many parts of Octave that will not work
00058   // correctly.
00059 
00060   octave_Inf = octave_NaN = octave_NA = DBL_MAX;
00061 
00062   oct_mach_info::float_format ff = oct_mach_info::native_float_format ();
00063 
00064   switch (ff)
00065     {
00066     case oct_mach_info::flt_fmt_ieee_big_endian:
00067     case oct_mach_info::flt_fmt_ieee_little_endian:
00068       {
00069         // Don't optimize away tmp_inf / tmp_inf to generate octave_NaN.
00070 
00071         volatile double tmp_inf;
00072 
00073 #if defined (SCO)
00074         volatile double tmp = 1.0;
00075         tmp_inf = 1.0 / (tmp - tmp);
00076 #elif defined (__alpha__) && defined (__osf__)
00077         extern unsigned int DINFINITY[2];
00078         tmp_inf =  (*(X_CAST(double *, DINFINITY)));
00079 #else
00080         double tmp = 1e+10;
00081         tmp_inf = tmp;
00082         for (;;)
00083           {
00084             tmp_inf *= 1e+10;
00085             if (tmp_inf == tmp)
00086               break;
00087             tmp = tmp_inf;
00088           }
00089 #endif
00090 
00091 #if defined (__alpha__) && defined (__osf__)
00092         extern unsigned int DQNAN[2];
00093         octave_NaN = (*(X_CAST(double *, DQNAN)));
00094 #else
00095         octave_NaN = tmp_inf / tmp_inf;
00096 #endif
00097 
00098         octave_Inf = tmp_inf;
00099 
00100         // This is patterned after code in R.
00101 
00102         if (ff == oct_mach_info::flt_fmt_ieee_big_endian)
00103           {
00104             lo_ieee_hw = 0;
00105             lo_ieee_lw = 1;
00106           }
00107         else
00108           {
00109             lo_ieee_hw = 1;
00110             lo_ieee_lw = 0;
00111           }
00112 
00113         lo_ieee_double t;
00114         t.word[lo_ieee_hw] = LO_IEEE_NA_HW;
00115         t.word[lo_ieee_lw] = LO_IEEE_NA_LW;
00116 
00117         octave_NA = t.value;
00118       }
00119       break;
00120 
00121     case oct_mach_info::flt_fmt_cray:
00122     case oct_mach_info::flt_fmt_vax_d:
00123     case oct_mach_info::flt_fmt_vax_g:
00124       break;
00125 
00126     default:
00127       // If the format is unknown, then you will probably not have a
00128       // useful system, but we will just issue a warning and go on...
00129       (*current_liboctave_warning_handler)
00130         ("lo_ieee_init: unrecognized floating point format!");
00131     }
00132 }
00133 
00134 /*
00135 ;;; Local Variables: ***
00136 ;;; mode: C++ ***
00137 ;;; End: ***
00138 */

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