Mercurial > hg > octave-nkf
changeset 1226:2457d4ba0691
[project @ 1995-04-10 00:41:14 by jwe]
author | jwe |
---|---|
date | Mon, 10 Apr 1995 00:41:32 +0000 |
parents | b013cff15746 |
children | 766e2a1a4e7b |
files | src/load-save.cc src/sysdep.cc |
diffstat | 2 files changed, 329 insertions(+), 235 deletions(-) [+] |
line wrap: on
line diff
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -39,6 +39,7 @@ #include "user-prefs.h" #include "unwind-prot.h" #include "load-save.h" +#include "sysdep.h" #include "symtab.h" #include "pager.h" #include "error.h" @@ -88,16 +89,6 @@ LS_UNKNOWN, }; -enum floating_point_format - { - LS_IEEE_LITTLE, - LS_IEEE_BIG, - LS_VAX_D, - LS_VAX_G, - LS_CRAY, - LS_UNKNOWN_FLT_FMT, - }; - // Not all of the following are currently used. enum save_type @@ -112,18 +103,6 @@ LS_DOUBLE, }; -#if defined (IEEE_LITTLE_ENDIAN) -#define NATIVE_FLOAT_FORMAT LS_IEEE_LITTLE -#elif defined (IEEE_BIG_ENDIAN) -#define NATIVE_FLOAT_FORMAT LS_IEEE_BIG -#elif defined (VAX_D_FLOAT) -#define NATIVE_FLOAT_FORMAT LS_VAX_D -#elif defined (VAX_G_FLOAT) -#define NATIVE_FLOAT_FORMAT LS_VAX_G -#else -LOSE! LOSE! -#endif - #define swap_1_bytes(x,y) #define LS_DO_READ(TYPE,swap,data,size,len,stream) \ @@ -230,8 +209,6 @@ // XXX FIXME XXX -- assumes sizeof (double) == 8 // XXX FIXME XXX -- assumes sizeof (float) == 4 -#if defined (IEEE_LITTLE_ENDIAN) - static void IEEE_big_double_to_IEEE_little_double (double *d, int len) { @@ -280,8 +257,6 @@ gripe_data_conversion ("Cray", "IEEE little endian format"); } -#elif defined (IEEE_BIG_ENDIAN) - static void IEEE_little_double_to_IEEE_big_double (double *d, int len) { @@ -330,8 +305,6 @@ gripe_data_conversion ("Cray", "IEEE big endian format"); } -#elif defined (VAX_D_FLOAT) - static void IEEE_little_double_to_VAX_D_double (double *d, int len) { @@ -380,8 +353,6 @@ gripe_data_conversion ("Cray", "VAX D"); } -#elif defined (VAX_G_FLOAT) - static void IEEE_little_double_to_VAX_G_double (double *d, int len) { @@ -430,105 +401,122 @@ gripe_data_conversion ("VAX G float", "VAX G"); } -#endif - static void do_double_format_conversion (double *data, int len, floating_point_format fmt) { - switch (fmt) + switch (native_float_format) { -#if defined (IEEE_LITTLE_ENDIAN) - - case LS_IEEE_LITTLE: - break; - - case LS_IEEE_BIG: - IEEE_big_double_to_IEEE_little_double (data, len); - break; - - case LS_VAX_D: - VAX_D_double_to_IEEE_little_double (data, len); - break; - - case LS_VAX_G: - VAX_G_double_to_IEEE_little_double (data, len); - break; - - case LS_CRAY: - Cray_to_IEEE_little_double (data, len); - break; - -#elif defined (IEEE_BIG_ENDIAN) - - case LS_IEEE_LITTLE: - IEEE_little_double_to_IEEE_big_double (data, len); - break; - - case LS_IEEE_BIG: - break; - - case LS_VAX_D: - VAX_D_double_to_IEEE_big_double (data, len); - break; - - case LS_VAX_G: - VAX_G_double_to_IEEE_big_double (data, len); - break; - - case LS_CRAY: - Cray_to_IEEE_big_double (data, len); - break; - -#elif defined (VAX_D_FLOAT) - - case LS_IEEE_LITTLE: - IEEE_little_double_to_VAX_D_double (data, len); - break; - - case LS_IEEE_BIG: - IEEE_big_double_to_VAX_D_double (data, len); - break; - - case LS_VAX_D: - break; - - case LS_VAX_G: - VAX_G_double_to_VAX_D_double (data, len); - break; - - case LS_CRAY: - Cray_to_VAX_D_double (data, len); - break; - -#elif defined (VAX_G_FLOAT) - - case LS_IEEE_LITTLE: - IEEE_little_double_to_VAX_G_double (data, len); - break; - - case LS_IEEE_BIG: - IEEE_big_double_to_VAX_G_double (data, len); - break; - - case LS_VAX_D: - VAX_D_double_to_VAX_G_double (data, len); - break; - - case LS_VAX_G: - break; - - case LS_CRAY: - Cray_to_VAX_G_double (data, len); - break; - -#else -LOSE! LOSE! -#endif + case OCTAVE_IEEE_LITTLE: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + break; + + case OCTAVE_IEEE_BIG: + IEEE_big_double_to_IEEE_little_double (data, len); + break; + + case OCTAVE_VAX_D: + VAX_D_double_to_IEEE_little_double (data, len); + break; + + case OCTAVE_VAX_G: + VAX_G_double_to_IEEE_little_double (data, len); + break; + + case OCTAVE_CRAY: + Cray_to_IEEE_little_double (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } + + case OCTAVE_IEEE_BIG: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + IEEE_little_double_to_IEEE_big_double (data, len); + break; + + case OCTAVE_IEEE_BIG: + break; + + case OCTAVE_VAX_D: + VAX_D_double_to_IEEE_big_double (data, len); + break; + + case OCTAVE_VAX_G: + VAX_G_double_to_IEEE_big_double (data, len); + break; + + case OCTAVE_CRAY: + Cray_to_IEEE_big_double (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } + + case OCTAVE_VAX_D: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + IEEE_little_double_to_VAX_D_double (data, len); + break; + + case OCTAVE_IEEE_BIG: + IEEE_big_double_to_VAX_D_double (data, len); + break; + + case OCTAVE_VAX_D: + break; + + case OCTAVE_VAX_G: + VAX_G_double_to_VAX_D_double (data, len); + break; + + case OCTAVE_CRAY: + Cray_to_VAX_D_double (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } + + case OCTAVE_VAX_G: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + IEEE_little_double_to_VAX_G_double (data, len); + break; + + case OCTAVE_IEEE_BIG: + IEEE_big_double_to_VAX_G_double (data, len); + break; + + case OCTAVE_VAX_D: + VAX_D_double_to_VAX_G_double (data, len); + break; + + case OCTAVE_VAX_G: + break; + + case OCTAVE_CRAY: + Cray_to_VAX_G_double (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } default: - gripe_unrecognized_float_fmt (); - break; + panic_impossible (); } } @@ -536,99 +524,118 @@ do_float_format_conversion (float *data, int len, floating_point_format fmt) { - switch (fmt) + switch (native_float_format) { -#if defined (IEEE_LITTLE_ENDIAN) - - case LS_IEEE_LITTLE: - break; - - case LS_IEEE_BIG: - IEEE_big_float_to_IEEE_little_float (data, len); - break; - - case LS_VAX_D: - VAX_D_float_to_IEEE_little_float (data, len); - break; - - case LS_VAX_G: - VAX_G_float_to_IEEE_little_float (data, len); - break; - - case LS_CRAY: - Cray_to_IEEE_little_float (data, len); - break; - -#elif defined (IEEE_BIG_ENDIAN) - - case LS_IEEE_LITTLE: - IEEE_little_float_to_IEEE_big_float (data, len); - break; - - case LS_IEEE_BIG: - break; - - case LS_VAX_D: - VAX_D_float_to_IEEE_big_float (data, len); - break; - - case LS_VAX_G: - VAX_G_float_to_IEEE_big_float (data, len); - break; - - case LS_CRAY: - Cray_to_IEEE_big_float (data, len); - break; - -#elif defined (VAX_D_FLOAT) - - case LS_IEEE_LITTLE: - IEEE_little_float_to_VAX_D_float (data, len); - break; - - case LS_IEEE_BIG: - IEEE_big_float_to_VAX_D_float (data, len); - break; - - case LS_VAX_D: - break; - - case LS_VAX_G: - VAX_G_float_to_VAX_D_float (data, len); - break; - - case LS_CRAY: - Cray_to_VAX_D_float (data, len); - break; - -#elif defined (VAX_G_FLOAT) - - case LS_IEEE_LITTLE: - IEEE_little_float_to_VAX_G_float (data, len); - break; - - case LS_IEEE_BIG: - IEEE_big_float_to_VAX_G_float (data, len); - break; - - case LS_VAX_D: - VAX_D_float_to_VAX_G_float (data, len); - break; - - case LS_VAX_G: - break; - - case LS_CRAY: - Cray_to_VAX_G_float (data, len); - break; - -#else -LOSE! LOSE! -#endif + case OCTAVE_IEEE_LITTLE: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + break; + + case OCTAVE_IEEE_BIG: + IEEE_big_float_to_IEEE_little_float (data, len); + break; + + case OCTAVE_VAX_D: + VAX_D_float_to_IEEE_little_float (data, len); + break; + + case OCTAVE_VAX_G: + VAX_G_float_to_IEEE_little_float (data, len); + break; + + case OCTAVE_CRAY: + Cray_to_IEEE_little_float (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } + + case OCTAVE_IEEE_BIG: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + IEEE_little_float_to_IEEE_big_float (data, len); + break; + + case OCTAVE_IEEE_BIG: + break; + + case OCTAVE_VAX_D: + VAX_D_float_to_IEEE_big_float (data, len); + break; + + case OCTAVE_VAX_G: + VAX_G_float_to_IEEE_big_float (data, len); + break; + + case OCTAVE_CRAY: + Cray_to_IEEE_big_float (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } + + case OCTAVE_VAX_D: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + IEEE_little_float_to_VAX_D_float (data, len); + break; + + case OCTAVE_IEEE_BIG: + IEEE_big_float_to_VAX_D_float (data, len); + break; + + case OCTAVE_VAX_D: + break; + + case OCTAVE_VAX_G: + VAX_G_float_to_VAX_D_float (data, len); + break; + + case OCTAVE_CRAY: + Cray_to_VAX_D_float (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } + + case OCTAVE_VAX_G: + switch (fmt) + { + case OCTAVE_IEEE_LITTLE: + IEEE_little_float_to_VAX_G_float (data, len); + break; + + case OCTAVE_IEEE_BIG: + IEEE_big_float_to_VAX_G_float (data, len); + break; + + case OCTAVE_VAX_D: + VAX_D_float_to_VAX_G_float (data, len); + break; + + case OCTAVE_VAX_G: + break; + + case OCTAVE_CRAY: + Cray_to_VAX_G_float (data, len); + break; + + default: + gripe_unrecognized_float_fmt (); + break; + } default: - gripe_unrecognized_float_fmt (); - break; + panic_impossible (); } } @@ -1717,32 +1724,32 @@ static floating_point_format get_floating_point_format (int mach) { - floating_point_format flt_fmt = LS_UNKNOWN_FLT_FMT; + floating_point_format flt_fmt = OCTAVE_UNKNOWN_FLT_FMT; switch (mach) { case 0: - flt_fmt = LS_IEEE_LITTLE; + flt_fmt = OCTAVE_IEEE_LITTLE; break; case 1: - flt_fmt = LS_IEEE_BIG; + flt_fmt = OCTAVE_IEEE_BIG; break; case 2: - flt_fmt = LS_VAX_D; + flt_fmt = OCTAVE_VAX_D; break; case 3: - flt_fmt = LS_VAX_G; + flt_fmt = OCTAVE_VAX_G; break; case 4: - flt_fmt = LS_CRAY; + flt_fmt = OCTAVE_CRAY; break; default: - flt_fmt = LS_UNKNOWN_FLT_FMT; + flt_fmt = OCTAVE_UNKNOWN_FLT_FMT; break; } @@ -1768,7 +1775,7 @@ // initialization of variable. Matrix re; - floating_point_format flt_fmt = LS_UNKNOWN_FLT_FMT; + floating_point_format flt_fmt = OCTAVE_UNKNOWN_FLT_FMT; char *name = 0; int swap = 0, type = 0, prec = 0, mach = 0, dlen = 0; @@ -1790,7 +1797,7 @@ mach = mopt % 10; // IEEE, VAX, etc. flt_fmt = get_floating_point_format (mach); - if (flt_fmt == LS_UNKNOWN_FLT_FMT) + if (flt_fmt == OCTAVE_UNKNOWN_FLT_FMT) { error ("load: unrecognized binary format!"); return 0; @@ -1910,7 +1917,7 @@ is.read (&tmp, 1); flt_fmt = get_floating_point_format (tmp); - if (flt_fmt == LS_UNKNOWN_FLT_FMT) + if (flt_fmt == OCTAVE_UNKNOWN_FLT_FMT) { if (! quiet) error ("load: unrecognized binary format!"); @@ -1934,7 +1941,7 @@ } int swap; - floating_point_format flt_fmt = LS_UNKNOWN_FLT_FMT; + floating_point_format flt_fmt = OCTAVE_UNKNOWN_FLT_FMT; if (read_binary_file_header (file, swap, flt_fmt, 1) == 0) retval = LS_BINARY; @@ -2158,7 +2165,7 @@ char *orig_fname = *argv; - floating_point_format flt_fmt = LS_UNKNOWN_FLT_FMT; + floating_point_format flt_fmt = OCTAVE_UNKNOWN_FLT_FMT; int swap = 0; @@ -2445,7 +2452,7 @@ FOUR_BYTE_INT mopt = 0; mopt += tc.is_string () ? 1 : 0; - mopt += 1000 * get_floating_point_format (NATIVE_FLOAT_FORMAT); + mopt += 1000 * get_floating_point_format (native_float_format); os.write (&mopt, 4); @@ -2845,7 +2852,7 @@ stream << "Octave-1-L"; #endif - char tmp = (char) NATIVE_FLOAT_FORMAT; + char tmp = (char) native_float_format; stream.write (&tmp, 1); } }
--- 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)