lo-ieee.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 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 3 of the License, or (at your
00010 option) any 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, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <cstdlib>
00028 
00029 #include <limits>
00030 
00031 #include "lo-error.h"
00032 #include "lo-ieee.h"
00033 #include "mach-info.h"
00034 
00035 void
00036 octave_ieee_init (void)
00037 {
00038   oct_mach_info::float_format ff = oct_mach_info::native_float_format ();
00039 
00040   switch (ff)
00041     {
00042     case oct_mach_info::flt_fmt_ieee_big_endian:
00043     case oct_mach_info::flt_fmt_ieee_little_endian:
00044       {
00045         octave_NaN = std::numeric_limits<double>::quiet_NaN ();
00046         octave_Inf = std::numeric_limits<double>::infinity ();
00047 
00048         octave_Float_NaN = std::numeric_limits<float>::quiet_NaN ();
00049         octave_Float_Inf = std::numeric_limits<float>::infinity ();
00050 
00051         // The following is patterned after code in R.
00052 
00053         if (ff == oct_mach_info::flt_fmt_ieee_big_endian)
00054           {
00055             lo_ieee_hw = 0;
00056             lo_ieee_lw = 1;
00057           }
00058         else
00059           {
00060             lo_ieee_hw = 1;
00061             lo_ieee_lw = 0;
00062           }
00063 
00064         lo_ieee_double t;
00065         t.word[lo_ieee_hw] = LO_IEEE_NA_HW;
00066         t.word[lo_ieee_lw] = LO_IEEE_NA_LW;
00067 
00068         octave_NA = t.value;
00069 
00070         lo_ieee_float tf;
00071         tf.word = LO_IEEE_NA_FLOAT;
00072         octave_Float_NA = tf.value;
00073       }
00074       break;
00075 
00076     case oct_mach_info::flt_fmt_cray:
00077     case oct_mach_info::flt_fmt_vax_d:
00078     case oct_mach_info::flt_fmt_vax_g:
00079     default:
00080       // If the format is unknown, then you will probably not have a
00081       // useful system, so we will abort here.  Anyone wishing to
00082       // experiment with building Octave on a system without IEEE
00083       // floating point should be capable of removing this check and
00084       // the configure test.
00085       (*current_liboctave_error_handler)
00086         ("lo_ieee_init: floating point format is not IEEE!  Maybe DLAMCH is miscompiled, or you are using some strange system without IEEE floating point math?");
00087       abort ();
00088     }
00089 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines