Mercurial > hg > octave-lyh
diff src/sysdep.cc @ 1226:2457d4ba0691
[project @ 1995-04-10 00:41:14 by jwe]
author | jwe |
---|---|
date | Mon, 10 Apr 1995 00:41:32 +0000 |
parents | b6360f2d4fa6 |
children | cb032139cb9f |
line wrap: on
line diff
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -52,6 +52,7 @@ #include "error.h" #include "sysdep.h" #include "defun.h" +#include "f77-uscore.h" extern "C" { @@ -69,6 +70,8 @@ #else LOSE! LOSE! #endif + +extern double F77_FCN (d1mach) (const int&); } #ifndef STDIN_FILENO @@ -81,6 +84,9 @@ // Octave's idea of not a number. double octave_NaN; +// The floating point format on this system. +floating_point_format native_float_format = OCTAVE_UNKNOWN_FLT_FMT; + #if defined (HAVE_FLOATINGPOINT_H) #include <floatingpoint.h> #endif @@ -110,6 +116,39 @@ } #endif +union equiv +{ + double d; + int i[2]; +}; + +struct float_params +{ + floating_point_format fp_fmt; + equiv fp_par[4]; +}; + +#define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2) \ + do \ + { \ + fp.fp_fmt = (fmt); \ + fp.fp_par[0].i[0] = (sm1); fp.fp_par[0].i[1] = (sm2); \ + fp.fp_par[1].i[0] = (lrg1); fp.fp_par[1].i[1] = (lrg2); \ + fp.fp_par[2].i[0] = (rt1); fp.fp_par[2].i[1] = (rt2); \ + fp.fp_par[3].i[0] = (dv1); fp.fp_par[3].i[1] = (dv2); \ + } \ + while (0) + +static int +equiv_compare (const equiv *std, const equiv *v, int len) +{ + int i; + for (i = 0; i < len; i++) + if (v[i].i[0] != std[i].i[0] || v[i].i[1] != std[i].i[1]) + return 0; + return 1; +} + static void octave_ieee_init (void) { @@ -157,6 +196,61 @@ octave_NaN = DBL_MAX; #endif + + float_params fp[5]; + + INIT_FLT_PAR (fp[0], OCTAVE_IEEE_BIG, + 1048576, 0, + 2146435071, -1, + 1017118720, 0, + 1018167296, 0); + + INIT_FLT_PAR (fp[1], OCTAVE_IEEE_LITTLE, + 0, 1048576, + -1, 2146435071, + 0, 1017118720, + 0, 1018167296); + + INIT_FLT_PAR (fp[2], OCTAVE_VAX_D, + 128, 0, + -32769, -1, + 9344, 0, + 9344, 0); + + INIT_FLT_PAR (fp[3], OCTAVE_VAX_G, + 16, 0, + -32769, -1, + 15552, 0, + 15552, 0); + + INIT_FLT_PAR (fp[4], OCTAVE_UNKNOWN_FLT_FMT, + 0, 0, + 0, 0, + 0, 0, + 0, 0); + + equiv mach_fp_par[4]; + + mach_fp_par[0].d = F77_FCN (d1mach) (1); + mach_fp_par[1].d = F77_FCN (d1mach) (2); + mach_fp_par[2].d = F77_FCN (d1mach) (3); + mach_fp_par[3].d = F77_FCN (d1mach) (4); + + int i = 0; + do + { + if (equiv_compare (fp[i].fp_par, mach_fp_par, 4)) + { + native_float_format = fp[i].fp_fmt; + break; + } + } + while (fp[++i].fp_fmt != OCTAVE_UNKNOWN_FLT_FMT); + + if (native_float_format == OCTAVE_UNKNOWN_FLT_FMT) + panic ("unrecognized floating point format!"); + + cerr << native_float_format << "\n"; } #if defined (EXCEPTION_IN_MATH) @@ -515,15 +609,8 @@ DEFUN ("isieee", Fisieee, Sisieee, 1, 1, "isieee (): return 1 if host uses IEEE floating point") { - Octave_object retval; - -#if defined (IEEE_BIG_ENDIAN) || defined (IEEE_LITTLE_ENDIAN) - retval = 1.0; -#else - retval = 0.0; -#endif - - return retval; + return (double) (native_float_format == OCTAVE_IEEE_LITTLE + || native_float_format == OCTAVE_IEEE_BIG); } #if !defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H)